main.cpp
来自「VC实现PING的各个参数,是学习SOCKET编程的 不错参考程序,代码清晰,可」· C++ 代码 · 共 44 行
CPP
44 行
#include "stdafx.h"
#include "ping.h"
void _tmain(int argc, TCHAR *argv[])
{
if (argc != 2)
{
printf("You must specify who you want to ping on the command line\n");
return;
}
#ifdef CPING_USE_ICMP
{
CPing p1;
CPingReply pr1;
if (p1.Ping1(argv[1], pr1))
{
hostent* phostent = gethostbyaddr((char *)&pr1.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr1.Address.S_un.S_un_b.s_b1, pr1.Address.S_un.S_un_b.s_b2, pr1.Address.S_un.S_un_b.s_b3,
pr1.Address.S_un.S_un_b.s_b4, phostent->h_name, pr1.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endif
#ifdef CPING_USE_WINSOCK2
{
CPing p2;
CPingReply pr2;
if (p2.Ping2(argv[1], pr2))
{
hostent* phostent = gethostbyaddr((char *)&pr2.Address.S_un.S_addr, 4, PF_INET);
printf("%d.%d.%d.%d [%s], replied in RTT:%dms\n",
pr2.Address.S_un.S_un_b.s_b1, pr2.Address.S_un.S_un_b.s_b2, pr2.Address.S_un.S_un_b.s_b3,
pr2.Address.S_un.S_un_b.s_b4, phostent->h_name, pr2.RTT);
}
else
printf("Failed in call to ping, GetLastError returns: %d", GetLastError());
}
#endif
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?