//*************************************************************** /* MGENとは、PPS等をスケジュール等で記載することが可能なUDPパケット ジェネレータである。 MGENは、プログラム開始時からUDPパケットに通番を付与する機能があり、 この番号を見張っていれば、ロストパケットを容易に発見することがで きる。 このプログラムは、MGENが生成したパケットを受信して、MGENのUDPの データエリアに付与された通番を使って、UDPのパケットロストを検知 するものである。 */ //*************************************************************** // mciprecv.cpp #include #include #include #include #define NO_FLAGS_SET 0 #define PORT (u_short) 5001 #define MAXBUFLEN 1500 INT main(VOID) { WSADATA Data; SOCKADDR_IN recvSockAddr; SOCKET recvSocket; int status; int numrcv; char buffer[MAXBUFLEN]; /* initialize the Windows Socket DLL */ status=WSAStartup(MAKEWORD(1, 1), &Data); if (status != 0) cerr << "ERROR: WSAStartup unsuccessful"<< endl; /* zero the sockaddr_in structure */ memset(&recvSockAddr, 0, sizeof(recvSockAddr)); /* specify the port portion of the address */ recvSockAddr.sin_port=htons(PORT); /* specify the address family as Internet */ recvSockAddr.sin_family=AF_INET; /* specify that the address does not matter */ recvSockAddr.sin_addr.s_addr=htonl(INADDR_ANY); /* create a socket */ recvSocket=socket(AF_INET, SOCK_DGRAM, 0); if (recvSocket == INVALID_SOCKET) cerr << "ERROR: socket unsuccessful" << endl; /* associate the socket with the address */ status=bind(recvSocket, (LPSOCKADDR) &recvSockAddr, sizeof(recvSockAddr)); if (status == SOCKET_ERROR) cerr << "ERROR: bind unsuccessful" << endl; // timer setup DWORD startTime = GetTickCount(); printf("start program .\n"); while(1) { numrcv=recvfrom(recvSocket, buffer, MAXBUFLEN, NO_FLAGS_SET, NULL, NULL); if (numrcv == SOCKET_ERROR) { cerr << "ERROR: recvfrom unsuccessful" << endl; status=closesocket(recvSocket); if (status == SOCKET_ERROR) cerr << "ERROR: closesocket unsuccessful" << endl; status=WSACleanup(); if (status == SOCKET_ERROR) cerr << "ERROR: WSACleanup unsuccessful" << endl; return(1); } static int a = -1; /////////////////////////////////////////// // MGENのパケット通番を抽出 int c; memcpy(&c, buffer+8, 4); c = htonl(c); /////////////////////////////////////////// a++; static int no = 0; // 正常受信パケット数 static int ab = 0; // 受信できなかったパケット数 if (a == c) // 通番が一致したら { no++; printf("o"); } else { printf("\ntime= %d:no = %d ", GetTickCount()-startTime, no); no = 0; /* while(a != c) { //printf("%d ",a); //printf("x"); a++; ab++; } */ ab = c - a; a = c; printf("ab = %d\n", ab); ab = 0; } } /* while */ }