于博的技术Blog

Just For Fun!

导航

Ping命令的实现

     PING (Packet InterNet Groper) 是一个非常有用的命令,它可以用来测试两个主机之间的连通性.PING使用了ICMP回送请求与回送回答报文.PING是应用层直接使用网络层ICMP的一个例子.它没有通过运输层的TCP或UDP.

     在Windows平台编程实现PING的最简单方法是调用Iphlpapi.dll这个动态链接库,引用以下几个函数:

     1. IcmpCreateFile(); // opens a handle on which IPv4 ICMP echo requests can be issued.

     2. IcmpSendEcho(); // sends an IPv4 ICMP echo request and returns any echo response replies.

                                  // The call returns when the time-out has expired or the reply buffer is filled.

     3. IcmpCloseHandle(); // closes a handle opened by a call to the IcmpCreateFile or Icmp6CreateFile functions.

以下是实现代码:

Code
101 }
102 


 

posted on 2009-02-19 12:09  于博  阅读(1899)  评论(3编辑  收藏  举报