代码编程——ping命令流程(图)

来源:百度知道 编辑:UC知道 时间:2024/08/31 06:13:31
需要一份PING命令的流程图,源代码最好是用C语言实现的,如果有源代码及详细注释就BETTER了,如果是中文注释那BEST了。
流程图~~买是来不及了,需要短期恶补。

不是我写的,找的。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define WIN32_LEAN_AND_MEAN
#include <winsock.h>
#pragma comment(lib, "Wsock32.lib")

#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0

//#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
#define ICMP_MIN (8 + 4) // minimum 8 byte icmp packet (just header + timestamp)

// IP header
typedef struct _tagX_iphdr
{
unsigned char h_len:4; // length of the header
unsigned char version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // total length of the packet

unsigned short ident; // unique identifier
unsigned short frag_and_flags; // flags

unsigned char ttl; // ttl
unsigned char proto;