void icmp_protocol (unsigned char * icmp_data)
{
Struct icmp_header * icmp_protocol;
Icmp_data icmp_protocol=(struct icmp_header *);
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Transport Layer: the Internet Control Message Protocol -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
The switch (icmp_protocol - & gt; Type) {
Case 0:
Printf (" Type: 0 (Echo (ping) the reply) \ n ");
Printf (" Code: % d \ nChecksum: 0 x % 4 x \ n ", icmp_protocol - & gt; Code, ntohs (icmp_protocol - & gt; Checksum));
break;
Case 8:
Printf (" Type: 8 (Echo request (ping)) \ n ");
Printf (" Code: % d \ nChecksum: 0 x % 4 x \ n ", icmp_protocol - & gt; Code, ntohs (icmp_protocol - & gt; Checksum));
break;
Case 3:
Printf (" Type: 3 (Destination unreachable) \ n ");
The switch (icmp_protocol - & gt; Code) {
Case 1:
Printf (" Code: 1 (Host unreachable) \ nChecksum: 0 x % 4 x ", ntohs (icmp_protocol - & gt; Checksum));
break;
Case 3:
Printf (" Code: 3 (Port unreachable) \ nChecksum: 0 x % 4 x ", ntohs (icmp_protocol - & gt; Checksum));
break;
Case 4:
Printf (" Code: 4 (Need sliced) \ nChecksum: 0 x % 4 x ", ntohs (icmp_protocol - & gt; Checksum));
break;
Default:
Printf (" Unknow code \ n ");
break;
}
Case 11:
Printf (" Type: 11 (Survival time timeout) ");
Printf (" Code: % d \ nChecksum: 0 x % 4 x ", icmp_protocol - & gt; Code, ntohs (icmp_protocol - & gt; Checksum));
break;
Default:
Printf (" Unknow type \ n ");
break;
}
Printf (" Identifier (BE) : % d "(0 x % 4 x), ntohs (icmp_protocol - & gt; Icd_id), ntohs (icmp_protocol - & gt; Icd_id));
Printf (" Sequence number (BE) : % d "(0 x % 4 x), ntohs (icmp_protocol - & gt; Icd_sequence), ntohs (icmp_protocol - & gt; Icd_sequence));
}
This is the header file
# # ifndef _BASIC_H_
# define _BASIC_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include
Struct ether_header
{
Unsigned char ether_dhost [6].//destination MAC
Unsigned char ether_shost [6].//source MAC
Unsigned short ether_type;//Ethernet type
};
Struct ip_header
{
Unsigned int ip_v: 4;//version
Unsigned int ip_hl: 4;//the header length
U_int8_t ip_tos;//the type of service
U_short ip_len;//total length
U_short ip_id.//identification
U_short ip_off;//fragment offset field
/* # define IP_RF 0 x8000//reserved fragment flag
# define IP_DF 0 x4000//dont fragment flag
# define IP_MF 0 x2000//more fragments could flag
# define IP_OFFMASK 0 x1fff//mask for fragmenting bits */
U_int8_t ip_ttl;//time to live
U_int8_t ip_p;//protocol
U_short ip_sum;//checksum
Struct in_addr ip_src ip_dst;//source and dest address
};
Struct arp_header
{
Unsigned short int ar_hrd;//the Format of the hardware address.
Unsigned short int ar_pro;//the Format of protocol address.
Unsigned char ar_hln;//the Length of the hardware address.
Unsigned char ar_pln;//Length of protocol address.
Unsigned short int ar_op;//ARP opcode (command).
U_int8_t arp_sha [6].//the sender hardware address
U_int8_t arp_spa [4].//sender protocol address
U_int8_t arp_tha [6].//the target hardware address
U_int8_t arp_tpa [4].//the target protocol address
};
Struct rarp_header
{
Unsigned short int rar_hrd;//the Format of the hardware address.
Unsigned short int rar_pro;//the Format of protocol address.
Unsigned char rar_hln;//the Length of the hardware address.
Unsigned char rar_pln;//Length of protocol address.
Unsigned short int rar_op;//ARP opcode (command).
U_int8_t rarp_sha [6].//the sender hardware address
U_int8_t rarp_spa [4].//sender protocol address
U_int8_t rarp_tha [6].//the target hardware address
U_int8_t rarp_tpa [4].//the target protocol address
};
Struct tcp_header
{
U_int16_t source;
U_int16_t dest.
U_int32_t seq.
U_int32_t ack_seq;
U_int16_t doff: 4;
U_int16_t res1:4;
U_int16_t res2:2;
U_int16_t urg: 1;
U_int16_t ack: 1;
U_int16_t PSH: 1;
U_int16_t RST: 1;
U_int16_t syn: 1;
U_int16_t fin: 1;
U_int16_t window;
U_int16_t check;
U_int16_t urg_ptr;
};
Struct udp_header
{
U_int16_t sport;
U_int16_t dport;
U_int16_t len.//udp length
U_int16_t check;//checksum
};
Struct icmp_header
{
U_int8_t type;//the message type
U_int8_t code;//type sub - code
U_int16_t checksum.//catalog.
U_int16_t icd_id;
U_int16_t icd_sequence;
/* union
{
U_char ih_pptr;//icmp_paramprob
Struct in_addr ih_gwaddr;//gateway address
Struct ih_idseq//echo datagram
{
U_int16_t icd_id;
U_int16_t icd_sequence;
} ih_idseq;
U_int32_t ih_void;
//icmp_unreach_needfrag
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull