|
| 1 | +#ifndef _IPHDR_H_ |
| 2 | +#define _IPHDR_H_ |
| 3 | + |
| 4 | +#include <pshpack1.h> |
| 5 | + |
| 6 | +// |
| 7 | +// IPv4 Header (without any IP options) |
| 8 | +// |
| 9 | +typedef struct ip_hdr |
| 10 | +{ |
| 11 | + unsigned char ip_verlen; // 4-bit IPv4 version |
| 12 | + // 4-bit header length (in 32-bit words) |
| 13 | + unsigned char ip_tos; // IP type of service |
| 14 | + unsigned short ip_totallength; // Total length |
| 15 | + unsigned short ip_id; // Unique identifier |
| 16 | + unsigned short ip_offset; // Fragment offset field |
| 17 | + unsigned char ip_ttl; // Time to live |
| 18 | + unsigned char ip_protocol; // Protocol(TCP,UDP etc) |
| 19 | + unsigned short ip_checksum; // IP checksum |
| 20 | + unsigned int ip_srcaddr; // Source address |
| 21 | + unsigned int ip_destaddr; // Source address |
| 22 | +} IPV4_HDR, * PIPV4_HDR, FAR* LPIPV4_HDR, iphdr; |
| 23 | + |
| 24 | +// |
| 25 | +// IPv6 Header |
| 26 | +// |
| 27 | +typedef struct ipv6_hdr |
| 28 | +{ |
| 29 | + unsigned long ipv6_vertcflow; // 4-bit IPv6 version |
| 30 | + // 8-bit traffic class |
| 31 | + // 20-bit flow label |
| 32 | + unsigned short ipv6_payloadlen; // payload length |
| 33 | + unsigned char ipv6_nexthdr; // next header protocol value |
| 34 | + unsigned char ipv6_hoplimit; // TTL |
| 35 | + struct in6_addr ipv6_srcaddr; // Source address |
| 36 | + struct in6_addr ipv6_destaddr; // Destination address |
| 37 | +} IPV6_HDR, * PIPV6_HDR, FAR* LPIPV6_HDR; |
| 38 | + |
| 39 | +// |
| 40 | +// IPv6 Fragmentation Header |
| 41 | +// |
| 42 | +typedef struct ipv6_fragment_hdr |
| 43 | +{ |
| 44 | + unsigned char ipv6_frag_nexthdr; // Next protocol header |
| 45 | + unsigned char ipv6_frag_reserved; // Reserved: zero |
| 46 | + unsigned short ipv6_frag_offset; // Offset of fragment |
| 47 | + unsigned long ipv6_frag_id; // Unique fragment ID |
| 48 | +} IPV6_FRAGMENT_HDR, * PIPV6_FRAGMENT_HDR, FAR* LPIPV6_FRAGMENT_HDR; |
| 49 | + |
| 50 | +// |
| 51 | +// Define the UDP header |
| 52 | +// |
| 53 | +typedef struct udp_hdr |
| 54 | +{ |
| 55 | + unsigned short src_portno; // Source port no. |
| 56 | + unsigned short dest_portno; // Dest. port no. |
| 57 | + unsigned short udp_length; // Udp packet length |
| 58 | + unsigned short udp_checksum; // Udp checksum |
| 59 | +} UDP_HDR, * PUDP_HDR, udphdr; |
| 60 | + |
| 61 | +// |
| 62 | +// Define the TCP header |
| 63 | +// |
| 64 | +typedef struct tcp_hdr |
| 65 | +{ |
| 66 | + unsigned short src_portno; // Source port no. |
| 67 | + unsigned short dest_portno; // Dest. port no. |
| 68 | + unsigned long seq_num; // Sequence number |
| 69 | + unsigned long ack_num; // Acknowledgement number; |
| 70 | + unsigned short lenflags; // Header length and flags |
| 71 | + unsigned short window_size; // Window size |
| 72 | + unsigned short tcp_checksum; // Checksum |
| 73 | + unsigned short tcp_urgentptr; // Urgent data? |
| 74 | +} TCP_HDR, * PTCP_HDR, tcphdr; |
| 75 | + |
| 76 | +// |
| 77 | +// Stucture to extract port numbers that overlays the UDP and TCP header |
| 78 | +// |
| 79 | +typedef struct port_hdr |
| 80 | +{ |
| 81 | + unsigned short src_portno; |
| 82 | + unsigned short dest_portno; |
| 83 | +} PORT_HDR, * PPORT_HDR; |
| 84 | + |
| 85 | +// |
| 86 | +// IGMP header |
| 87 | +// |
| 88 | +typedef struct igmp_hdr |
| 89 | +{ |
| 90 | + unsigned char version_type; |
| 91 | + unsigned char max_resp_time; |
| 92 | + unsigned short checksum; |
| 93 | + unsigned long group_addr; |
| 94 | +} IGMP_HDR, * PIGMP_HDR; |
| 95 | + |
| 96 | +typedef struct igmp_hdr_query_v3 |
| 97 | +{ |
| 98 | + unsigned char type; |
| 99 | + unsigned char max_resp_time; |
| 100 | + unsigned short checksum; |
| 101 | + unsigned long group_addr; |
| 102 | + unsigned char resv_suppr_robust; |
| 103 | + unsigned char qqi; |
| 104 | + unsigned short num_sources; |
| 105 | + unsigned long sources[1]; |
| 106 | +} IGMP_HDR_QUERY_V3, * PIGMP_HDR_QUERY_V3; |
| 107 | + |
| 108 | +typedef struct igmp_group_record_v3 |
| 109 | +{ |
| 110 | + unsigned char type; |
| 111 | + unsigned char aux_data_len; |
| 112 | + unsigned short num_sources; |
| 113 | + unsigned long group_addr; |
| 114 | + unsigned long source_addr[1]; |
| 115 | +} IGMP_GROUP_RECORD_V3, * PIGMP_GROUP_RECORD_V3; |
| 116 | + |
| 117 | +typedef struct igmp_hdr_report_v3 |
| 118 | +{ |
| 119 | + unsigned char type; |
| 120 | + unsigned char reserved1; |
| 121 | + unsigned short checksum; |
| 122 | + unsigned short reserved2; |
| 123 | + unsigned short num_records; |
| 124 | +} IGMP_HDR_REPORT_V3, * PIGMP_HDR_REPORT_V3; |
| 125 | + |
| 126 | +#include <poppack.h> |
| 127 | + |
| 128 | +#endif |
| 129 | + |
| 130 | + |
0 commit comments