#pragma once #pragma pack(1) // Ethernet Header #define ETH_ALEN 6 /* Octets in one ethernet addr */ #define ETH_P_IP 0x0800 /* Internet Protocol packet */ #define ETH_P_ARP 0x0806 /* Address Resolution packet */ typedef struct _ethhdr { UCHAR h_dest[ETH_ALEN]; /* destination eth addr */ UCHAR h_source[ETH_ALEN]; /* source ether addr */ USHORT h_proto; /* packet type ID field */ } EthHdr; // ARP Header #define ARPOP_REQUEST 1 /* ARP request */ #define ARPOP_REPLY 2 /* ARP reply */ typedef struct _arphdr { USHORT ar_hrd; /* format of hardware address */ USHORT ar_pro; /* format of protocol address */ UCHAR ar_hln; /* length of hardware address */ UCHAR ar_pln; /* length of protocol address */ USHORT ar_op; /* ARP opcode (command) */ UCHAR ar_sha[ETH_ALEN]; /* sender hardware address */ ULONG ar_sip; /* sender IP address */ UCHAR ar_tha[ETH_ALEN]; /* target hardware address */ ULONG ar_tip; /* target IP address */ } ArpHdr; // IP Header #define IPPROTO_ICMP 1 /* Internet Control Message Protocol. */ #define IPPROTO_TCP 6 /* Transmission Control Protocol. */ #define IPPROTO_UDP 17 /* User Datagram Protocol. */ typedef struct _iphdr { UCHAR ihl:4; UCHAR version:4; UCHAR tos; USHORT tot_len; USHORT id; USHORT frag_off; UCHAR ttl; UCHAR protocol; USHORT check; ULONG saddr; ULONG daddr; } IpHdr; // ICMP Header #define ICMP_ECHOREPLY 0 /* Echo Reply */ #define ICMP_ECHO 8 /* Echo Request */ typedef struct _icmphdr { UCHAR type; /* message type */ UCHAR code; /* type sub-code */ USHORT checksum; union { struct { USHORT id; USHORT sequence; } echo; /* echo datagram */ ULONG gateway; /* gateway address */ struct { USHORT __unused; USHORT mtu; } frag; /* path mtu discovery */ } un; } IcmpHdr;