// Operations public: CIcmp(void); CIcmp(CIcmp ©); ~CIcmp(void); public: // I/O Buffer Pointers LPIcmpHeader pIcmpHeader; LPIpHeader pIpHeader;
SOCKET icmpSocket; SOCKADDR_IN icmpSockAddr; SOCKADDR_IN rcvSockAddr; DWORD icmpRoundTripTime; DWORD icmpPingSentAt; DWORD icmpPingReceivedAt;
int icmpRcvLen; int icmpHops; int icmpMaxHops; int icmpCurSeq; int icmpCurId; int icmpPingTimer; int icmpSocketError; int icmpSocketErrorMod; unsigned long icmpHostAddress; protected: };
初始化网络连接的函数:
BOOL CIcmp::Connect(LPINT ReceiveTimeout, LPINT SendTimeout, int AFamily, int AType, int AProtocol) { int Result; icmpSocket = NULL; icmpSocket = socket(AFamily, AType, AProtocol);
if (icmpSocket == INVALID_SOCKET) { icmpSocketError = WSAGetLastError(); icmpSocketErrorMod = 1; return FALSE; }
// // Set receive timeout //
Result = setsockopt(icmpSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)ReceiveTimeout, sizeof(int)); if (Result == SOCKET_ERROR) { icmpSocketError = WSAGetLastError(); icmpSocketErrorMod = 2; closesocket(icmpSocket); icmpSocket = INVALID_SOCKET; return FALSE; }
// // Set send timeout // Result = setsockopt(icmpSocket, SOL_SOCKET, SO_SNDTIMEO, (char*)SendTimeout,sizeof(int)); if (Result == SOCKET_ERROR) { icmpSocketError = WSAGetLastError(); icmpSocketErrorMod = 3; closesocket(icmpSocket); icmpSocket = INVALID_SOCKET; return FALSE; } icmpCurSeq = 0; icmpCurId = (USHORT)GetCurrentProcessId(); icmpHops = 0;
return TRUE; }
共9页: 上一页 [1] [2] [3] [4] [5] [6] 7 [8] [9] 下一页
|