ping 源码
http://www.xici.net 作者: 大鹰 (2001-05-12 10:57:18)
记得 W.richard stevens 的一句话,学习编码的最好方法即读懂大量编码。
/* PING.C
/*
/* ping source code distribute by cpu || digger.
/* for unix family only. compil and link success in sco unix.
/* i think linux no problem too. u can try it.
/* before read this code, you shoud know about the principle of
/* tcp/ip, especially icmp protocol, u also should also know some
/* about BSD socket API, and unix system signal programming.
/*
/* cc -o ping ping.c -lsocket, then u will get executable file,
/* but must act as root when cc it, and then set euid attribute
/* for this ping, then u can execute it as common user.
/* because only root can have authority to creat raw socket.
/*
/* i love socket, if so do u,
/* call me, cpu == digger
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# define ICMP_ECHO 8 /* icmp echo requir */
# define ICMP_ECHOREPLY 0 /* icmp echo reply */
# define ICMP_HEADSIZE 8 /* icmp packet header size */
# define IP_HEADSIZE 20 /* ip packet header size */
typedef struct tagIpHead /* icmp packet header */
{
u_char ip_verlen; /* ip version and ip header lenth*/
u_char ip_tos; /* ip type of service */
u_short ip_len; /* ip packet lenghth */
u_short ip_id; /* ip packet identification */
u_short ip_fragoff; /* ip packet fragment and offset */
u_char ip_ttl; /* ip packet time to live */