This is a low-level network debugging utility that utilizes raw packet i/o to construct and deconstruct tcp, udp, ipv4, arp, and icmp packets over ethernet.
net/arp.h@0:d494b853ce97, 2010-10-12 (annotated)
- Committer:
- etherealflaim
- Date:
- Tue Oct 12 05:32:59 2010 +0000
- Revision:
- 0:d494b853ce97
- Child:
- 1:63d4ff534d65
Initial Publish - Slightly unfinished, but usable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
etherealflaim | 0:d494b853ce97 | 1 | #ifndef ARP_H |
etherealflaim | 0:d494b853ce97 | 2 | #define ARP_H |
etherealflaim | 0:d494b853ce97 | 3 | |
etherealflaim | 0:d494b853ce97 | 4 | #include "net.h" |
etherealflaim | 0:d494b853ce97 | 5 | |
etherealflaim | 0:d494b853ce97 | 6 | #define ETHERTYPE_ARP 0x0806 |
etherealflaim | 0:d494b853ce97 | 7 | typedef struct { |
etherealflaim | 0:d494b853ce97 | 8 | u16 hardware_type; // 0x0001 for ethernet |
etherealflaim | 0:d494b853ce97 | 9 | u16 protocol_type; // 0x0800 for IPv4 |
etherealflaim | 0:d494b853ce97 | 10 | u8 hardware_length; // Bytes. Ethernet is 6 |
etherealflaim | 0:d494b853ce97 | 11 | u8 protocol_length; // Bytes. IPv4 is 4 |
etherealflaim | 0:d494b853ce97 | 12 | u16 operation; // Operation. 1 for request, 2 for reply or announce |
etherealflaim | 0:d494b853ce97 | 13 | // The following are only valid for IPv4 over Ethernet |
etherealflaim | 0:d494b853ce97 | 14 | u8 sender_hardware_address[6]; // Generator of the request or reply |
etherealflaim | 0:d494b853ce97 | 15 | u8 sender_protocol_address[4]; // All zeroes for an ARP probe |
etherealflaim | 0:d494b853ce97 | 16 | u8 target_hardware_address[6]; // Announce - same as SHA |
etherealflaim | 0:d494b853ce97 | 17 | u8 target_protocol_address[4]; // Announce - Same as TPA |
etherealflaim | 0:d494b853ce97 | 18 | } ARP_Packet; |
etherealflaim | 0:d494b853ce97 | 19 | |
etherealflaim | 0:d494b853ce97 | 20 | inline void fix_endian_arp(ARP_Packet *packet) |
etherealflaim | 0:d494b853ce97 | 21 | { |
etherealflaim | 0:d494b853ce97 | 22 | fix_endian_u16(&packet->hardware_type); |
etherealflaim | 0:d494b853ce97 | 23 | fix_endian_u16(&packet->protocol_type); |
etherealflaim | 0:d494b853ce97 | 24 | fix_endian_u16(&packet->operation); |
etherealflaim | 0:d494b853ce97 | 25 | } |
etherealflaim | 0:d494b853ce97 | 26 | |
etherealflaim | 0:d494b853ce97 | 27 | inline void print_arp(ARP_Packet *packet) |
etherealflaim | 0:d494b853ce97 | 28 | { |
etherealflaim | 0:d494b853ce97 | 29 | main_log.printf("ARP Packet:"); |
etherealflaim | 0:d494b853ce97 | 30 | main_log.printf(" Hardware: 0x%04X", packet->hardware_type); |
etherealflaim | 0:d494b853ce97 | 31 | main_log.printf(" Protocol: 0x%04X", packet->protocol_type); |
etherealflaim | 0:d494b853ce97 | 32 | main_log.printf(" Type: %d", packet->operation); |
etherealflaim | 0:d494b853ce97 | 33 | if (packet->hardware_type != 0x0001 || packet->protocol_type != 0x0800) return; |
etherealflaim | 0:d494b853ce97 | 34 | |
etherealflaim | 0:d494b853ce97 | 35 | u8 *bytes; |
etherealflaim | 0:d494b853ce97 | 36 | bytes = packet->sender_hardware_address; |
etherealflaim | 0:d494b853ce97 | 37 | main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); |
etherealflaim | 0:d494b853ce97 | 38 | bytes = packet->target_hardware_address; |
etherealflaim | 0:d494b853ce97 | 39 | main_log.printf(" Target: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); |
etherealflaim | 0:d494b853ce97 | 40 | bytes = packet->sender_protocol_address; |
etherealflaim | 0:d494b853ce97 | 41 | main_log.printf(" Source: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); |
etherealflaim | 0:d494b853ce97 | 42 | bytes = packet->target_protocol_address; |
etherealflaim | 0:d494b853ce97 | 43 | main_log.printf(" Target: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); |
etherealflaim | 0:d494b853ce97 | 44 | } |
etherealflaim | 0:d494b853ce97 | 45 | |
etherealflaim | 0:d494b853ce97 | 46 | #endif |