异步通知主窗口:
int CIcmp::SetAsynchNotification(HWND hWnd, unsigned int Message, long Events) { int Result = WSAAsyncSelect (icmpSocket,hWnd, Message, Events); if (Result == SOCKET_ERROR) { icmpSocketError = WSAGetLastError(); icmpSocketErrorMod = 1; icmpSocket = INVALID_SOCKET; } return Result; }
设置TTL:
int CIcmp::SetTTL(int TTL) { int Result; Result = setsockopt (icmpSocket, IPPROTO_IP, IP_TTL, (LPSTR)&TTL, sizeof(int));
if (Result == SOCKET_ERROR) { icmpSocketErrorMod = 1; icmpSocketError = WSAGetLastError(); } return Result; }
Ping命令的函数:
int CIcmp::Ping (LPSTR pIcmpBuffer, int DataLen) { int Result; int IcmpBufferSize = DataLen + IcmpHeaderLength; pIcmpHeader = (LPIcmpHeader)pIcmpBuffer;
memset (pIcmpBuffer, 'E', IcmpBufferSize); memset (pIcmpHeader, 0, IcmpHeaderLength);
pIcmpHeader->IcmpType = ICMP_ECHO; pIcmpHeader->IcmpCode = 0; pIcmpHeader->IcmpChecksum = 0; pIcmpHeader->IcmpId = icmpCurId; pIcmpHeader->IcmpSeq = icmpCurSeq; pIcmpHeader->IcmpTimestamp = GetCurrentTime();
pIcmpHeader->IcmpChecksum = IcmpChecksum ((USHORT FAR *)pIcmpBuffer,IcmpBufferSize);
icmpPingSentAt = GetCurrentTime(); Result = sendto (icmpSocket, pIcmpBuffer, IcmpBufferSize, 0, (LPSOCKADDR)&icmpSockAddr, sizeof icmpSockAddr);
if (Result == SOCKET_ERROR) { icmpSocketError = WSAGetLastError(); icmpSocketErrorMod = 1; } return Result; }
(参考链接: http://dev.yesky.com/139/2663639.shtml)
共9页: 上一页 [1] [2] [3] [4] [5] [6] [7] [8] 9 下一页
|