⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 VC实现PING的各个参数,是学习SOCKET编程的 不错参考程序,代码清晰,可读性好
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -