14 static const uint16_t UDP_PORT_DHCP_SERVER = 67;
15 static const uint16_t UDP_PORT_DHCP_CLIENT = 68;
16 static const uint16_t UDP_PORT_NBNS = 137;
18 static const unsigned int MAX_FRAME_LEN = 1524;
20 typedef struct tagMacAddr {
22 bool operator ==(
const tagMacAddr& other)
const {
23 return ((v[0] == other.v[0]) && (v[1] == other.v[1]) && (v[2] == other.v[2]) && (v[3] == other.v[3]) && (v[4] == other.v[4]) && (v[5] == other.v[5]));
26 bool operator !=(
const tagMacAddr& other)
const {
27 return !((v[0] == other.v[0]) && (v[1] == other.v[1]) && (v[2] == other.v[2]) && (v[3] == other.v[3]) && (v[4] == other.v[4])
28 && (v[5] == other.v[5]));
31 }__attribute__((packed)) MAC_ADDR;
33 static const MAC_ADDR MAC_BROADCAST;
46 }__attribute__((packed)) MAC_HEADER;
48 typedef union tagIpAddr {
51 bool operator ==(
const tagIpAddr& other)
const {
52 return (val == other.val);
54 }__attribute__((packed)) IP_ADDR;
56 static const IP_ADDR IP_BROADCAST;
71 }__attribute__((packed)) IP_PSEUDO_HEADER;
76 uint8_t typeOfService;
78 uint16_t identification;
79 uint16_t fragmentInfo;
82 uint16_t headerChecksum;
85 }__attribute__((packed)) IP_HEADER;
89 ARP_HW_TYPE_ETHERNET = 0x0001
94 ARP_PROTOCOL_IP = 0x0800
99 ARP_OPERATION_REQ = 0x01,
100 ARP_OPERATION_RESP = 0x02
104 ARP_HW_TYPE hardwareType;
105 ARP_PROTOCOL protocol;
108 ARP_OPERATION operation;
113 }__attribute__((packed)) ARP_HEADER;
117 ICMP_TYPE_ECHO_REPLY = 0,
118 ICMP_TYPE_ECHO_REQUEST = 8
127 }__attribute__((packed)) ICMP_HEADER;
129 typedef uint16_t UDP_PORT;
136 }__attribute__((packed)) UDP_HEADER;
138 static const
int UDP_MAX_DATA_LEN = MAX_FRAME_LEN - sizeof(MAC_HEADER) - sizeof(IP_HEADER) - sizeof(UDP_HEADER);
140 typedef uint16_t TCP_PORT;
142 const static uint8_t TCP_FLAG_FIN = 0x01;
143 const static uint8_t TCP_FLAG_SYN = 0x02;
144 const static uint8_t TCP_FLAG_RST = 0x04;
145 const static uint8_t TCP_FLAG_PSH = 0x08;
146 const static uint8_t TCP_FLAG_ACK = 0x10;
147 const static uint8_t TCP_FLAG_URG = 0x20;
149 typedef union tagTCP_FLAGS {
174 uint16_t urgentPointer;
175 }__attribute__((packed)) TCP_HEADER;
181 }__attribute__((packed)) TCP_HEADER_OPTIONS;
183 static const
int TCP_MAX_DATA_LEN = MAX_FRAME_LEN - sizeof(MAC_HEADER) - sizeof(IP_HEADER) - sizeof(TCP_HEADER);
187 DHCP_OPCODE_BOOT_REQUEST = 1,
188 DHCP_OPCODE_BOOT_REPLY = 2
191 static const uint8_t DHCP_MAGIC_COOKIE[4];
195 uint8_t hardwareType;
198 uint32_t transactionID;
199 uint16_t numberOfSeconds;
201 IP_ADDR clientIpAddr;
203 IP_ADDR serverIpAddr;
204 IP_ADDR gatewayIpAddr;
205 uint8_t clientHwAddr[16];
206 uint8_t serverHostName[64];
207 uint8_t bootFileName[128];
208 }__attribute__((packed)) DHCP_HEADER;
210 static const uint16_t NBNS_TYPE_NB = 0x0020;
211 static const uint16_t NBNS_TYPE_NBSTAT = 0x0021;
212 static const uint16_t NBNS_CLASS_IN = 0x0001;
219 uint16_t authorities;
220 uint16_t additionals;
221 }__attribute__((packed)) NBNS_HEADER;
240 uint16_t questionCount;
241 uint16_t answerRecordCount;
242 uint16_t authorityRecordCount;
243 uint16_t additionalRecordCount;
244 }__attribute__((packed)) DNS_HEADER;
249 }__attribute__((packed)) DNS_PKT;
251 typedef struct tagFRAME {
254 uint8_t raw[MAX_FRAME_LEN];
257 MAC_HEADER macHeader;
258 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER)];
262 MAC_HEADER macHeader;
263 ARP_HEADER arpHeader;
264 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(ARP_HEADER)];
268 MAC_HEADER macHeader;
270 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER)];
274 MAC_HEADER macHeader;
276 ICMP_HEADER icmpHeader;
277 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(ICMP_HEADER)];
281 MAC_HEADER macHeader;
283 UDP_HEADER udpHeader;
284 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(UDP_HEADER)];
288 MAC_HEADER macHeader;
290 UDP_HEADER udpHeader;
291 DHCP_HEADER dhcpHeader;
292 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(UDP_HEADER) -
sizeof(DHCP_HEADER)];
296 MAC_HEADER macHeader;
298 UDP_HEADER udpHeader;
299 NBNS_HEADER nbnsHeader;
300 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(UDP_HEADER) -
sizeof(NBNS_HEADER)];
304 MAC_HEADER macHeader;
306 TCP_HEADER tcpHeader;
307 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(TCP_HEADER)];
311 MAC_HEADER macHeader;
313 TCP_HEADER tcpHeader;
314 TCP_HEADER_OPTIONS tcpOptions;
315 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(TCP_HEADER) -
sizeof(TCP_HEADER_OPTIONS)];
319 MAC_HEADER macHeader;
321 UDP_HEADER udpHeader;
322 DNS_HEADER dnsHeader;
323 uint8_t data[MAX_FRAME_LEN -
sizeof(MAC_HEADER) -
sizeof(IP_HEADER) -
sizeof(UDP_HEADER) -
sizeof(DNS_HEADER)];
327 }__attribute__((packed)) FRAME;
332 IP_ADDR gatewayIpAddr;
336 }__attribute__((packed)) NET_CONFIG;