int(lobyte(loword(pipe->address))) << "." <<
int(hibyte(loword(pipe->address))) << "." <<
int(lobyte(hiword(pipe->address))) << "." <<
int(hibyte(hiword(pipe->address))) << ", " <<
"rtt: " << int(pipe->roundtriptime) << "ms, " <<
"ttl: " << int(pipe->options.ttl) << endl;
}
else {
cerr << "error obtaining info from ping packet." << endl;
}
// 关闭,回收资源
globalfree(pipe);
freelibrary(hicmp);
return 0;
}
==================主函数==================
int main(int argc, char* argv[])
{
wsadata wsadata;
if (wsastartup(makeword(1, 1), &wsadata) != 0) {
return 255;
}
int retval = doit(argc, argv);
wsacleanup();
return retval;
}
==================头文件==================
icmpdefs.h
//icmp.dll 函数中需要的结构
typedef struct {
unsigned char ttl; // time to live
unsigned char tos; // type of service
unsigned char flags; // ip header flags
unsigned char optionssize; // size in bytes of options data
unsigned char *optionsdata; // pointer to options data
} ip_option_information, * pip_option_information;
typedef struct {
dword address; // replying address
unsigned long status; // reply status
unsigned long roundtriptime; // rtt in milliseconds
unsigned short datasize; // echo data size
unsigned short reserved; // reserved for system use
void *data; // pointer to the echo data
ip_option_information options; // reply options
} ip_echo_reply, * pip_echo_reply;
链接:
-------
我的其它文章,<<透析icmp协议>>, 和其它文章参见:
http://www.csdn.net/develop/author/netauthor/bugfree/
联系方式:
-------