?? myping.cpp
字號:
// MyPing.cpp: implementation of the CMyPing class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Ping.h"
#include "MyPing.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMyPing::CMyPing()
{
}
CMyPing::~CMyPing()
{
}
//DEL void CMyPing::Ping(UINT nRetries, LPCSTR pstrHost, HWND hwnd)
//DEL {
//DEL
//DEL }
//DEL int CMyPing::WaitForEchoReply(SCOKET s)
//DEL {
//DEL
//DEL }
//DEL int CMyPing::SendEchoReply(SCOKET, LPSOCKADDR_IN)
//DEL {
//DEL
//DEL }
DWORD CMyPing::RecxEchoReply(SOCKET, LPSOCKADDR_IN, u_char *)
{
}
int CMyPing::WaitForEchoReply(SOCKET s)
{
}
int CMyPing::SendEchoRequest(SOCKET, LPSOCKADDR_IN)
{
}
u_short CMyPing::in_cksum(u_short *addr, int len)
{
}
void CMyPing::WSAError(LPCSTR pstrFrom)
{
}
void CMyPing::Ping(UINT nRetries, LPCSTR pstrHost, HWND hWnd)
{
SOCKET rawSocket;
LPHOSTENT lpHost;
UINT nLoop;
int nRet;
struct sockaddr_in saDest;
struct sockaddr_in saSrc;
DWORD dwTimeSent;
DWORD dwElapsed;
u_char cTTL;
m_hWnd=hWnd;
CString str;
ASSERT(IsWindow(hWnd));
rawSocket=socket(AF_INET,SOCK_RAW<IPPROTO_ICMP);
if(rawSocket==SOCKET_ERROR)
{
WSAError("socket()");
return;
}
lpHost=gethostbyname(pstrHost);
if(lpHost==NULL)
{
str.Format("Host not found:%s",pstrHost);
::PostMessage(m_hWnd,WM_MSG_STATUS,0,(LPARAM)AllocBuffer(str));
::PostMessage(m_hWnd,WM_PING_END,0,0);
return;
}
saDest.sin_addr.s_addr=*((u_long FAR*)(lpHost->h_addr));
saDest.sin_family=AF_INET;
saDest.sin_port=0;
str.Format("Pinging %s[%s] with %d bytes of data:",
pstrhost,
inet_ntoa(saDest.sin_addr),
REQ_DATASIZE);
::PostMessage(m_hWnd,WM_MSG_STATUS,1,(LPARAM)AllocBuffer(str));
for(nLoop=0;nLoop<nRetries;nLoop++0
{
SendEchoRequest(rawSocket,&saDest);
nRet=WaitForEchoReply(rawSocket);
if(nRet==SOCKET_ERROR)
{
WSAError("select()");
break;
}
if(!nRet)
{
str.Format("Request Timed Out");
::PostMessage(m_hWnd,WN_MSG_STATUS,3,(LPARAM)AllocBuffer(str));
}
else
{
dwTimeSent=RecvEchoReply(rawSocket,&saSrc,&cTTL);
dwElapsed=GetTickCount()-dwTimeSent;
str.Foemat("Reply[%d] from:%s:bytes=%d
time=%ldms TTL=%d",
nLoop+1,
inet_ntoa(asSrc.sin_addr),
REQ_DATASIZE,
dwElapsed,
cTTL);
::PostMessage(m_hWnd,WM_MSG_STATUS,2,(LPARAM)AllocBuffer(str));
Sleep(1000);
}
}
::PostMessage(m_hWnd,WM_PING_END,0,1);
nRet=closesocket(rawSocket);
if(nRet==SOCKET_ERROR)
WSAError("closesocket()");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -