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@8:1c1f6ce348c6, 2010-10-12 (annotated)
- Committer:
- etherealflaim
- Date:
- Tue Oct 12 06:48:59 2010 +0000
- Revision:
- 8:1c1f6ce348c6
- Parent:
- 5:c56386b9fc33
Documentation
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 | 5:c56386b9fc33 | 6 | /** |
etherealflaim | 5:c56386b9fc33 | 7 | \file |
etherealflaim | 5:c56386b9fc33 | 8 | \brief ARP packet |
etherealflaim | 5:c56386b9fc33 | 9 | |
etherealflaim | 5:c56386b9fc33 | 10 | This file contains the memory map and associated functions for ARP packet |
etherealflaim | 5:c56386b9fc33 | 11 | creation and deconstruction. |
etherealflaim | 5:c56386b9fc33 | 12 | */ |
etherealflaim | 5:c56386b9fc33 | 13 | |
etherealflaim | 0:d494b853ce97 | 14 | #define ETHERTYPE_ARP 0x0806 |
etherealflaim | 1:63d4ff534d65 | 15 | |
etherealflaim | 3:c32d9660b888 | 16 | /// ARP Packet memory map |
etherealflaim | 0:d494b853ce97 | 17 | typedef struct { |
etherealflaim | 1:63d4ff534d65 | 18 | u16 hardware_type; ///< 0x0001 for ethernet |
etherealflaim | 1:63d4ff534d65 | 19 | u16 protocol_type; ///< 0x0800 for IPv4 |
etherealflaim | 1:63d4ff534d65 | 20 | u8 hardware_length; ///< Bytes. Ethernet is 6 |
etherealflaim | 1:63d4ff534d65 | 21 | u8 protocol_length; ///< Bytes. IPv4 is 4 |
etherealflaim | 1:63d4ff534d65 | 22 | u16 operation; ///< Operation. 1 for request, 2 for reply or announce |
etherealflaim | 0:d494b853ce97 | 23 | // The following are only valid for IPv4 over Ethernet |
etherealflaim | 1:63d4ff534d65 | 24 | u8 sender_hardware_address[6]; ///< Generator of the request or reply |
etherealflaim | 1:63d4ff534d65 | 25 | u8 sender_protocol_address[4]; ///< All zeroes for an ARP probe |
etherealflaim | 1:63d4ff534d65 | 26 | u8 target_hardware_address[6]; ///< Announce - same as SHA |
etherealflaim | 1:63d4ff534d65 | 27 | u8 target_protocol_address[4]; ///< Announce - Same as TPA |
etherealflaim | 0:d494b853ce97 | 28 | } ARP_Packet; |
etherealflaim | 0:d494b853ce97 | 29 | |
etherealflaim | 2:e8e09adc41fc | 30 | /// Convert from wire to host or host to wire endianness |
etherealflaim | 0:d494b853ce97 | 31 | inline void fix_endian_arp(ARP_Packet *packet) |
etherealflaim | 0:d494b853ce97 | 32 | { |
etherealflaim | 0:d494b853ce97 | 33 | fix_endian_u16(&packet->hardware_type); |
etherealflaim | 0:d494b853ce97 | 34 | fix_endian_u16(&packet->protocol_type); |
etherealflaim | 0:d494b853ce97 | 35 | fix_endian_u16(&packet->operation); |
etherealflaim | 0:d494b853ce97 | 36 | } |
etherealflaim | 0:d494b853ce97 | 37 | |
etherealflaim | 2:e8e09adc41fc | 38 | /// Print the ARP packet |
etherealflaim | 0:d494b853ce97 | 39 | inline void print_arp(ARP_Packet *packet) |
etherealflaim | 0:d494b853ce97 | 40 | { |
etherealflaim | 0:d494b853ce97 | 41 | main_log.printf("ARP Packet:"); |
etherealflaim | 0:d494b853ce97 | 42 | main_log.printf(" Hardware: 0x%04X", packet->hardware_type); |
etherealflaim | 0:d494b853ce97 | 43 | main_log.printf(" Protocol: 0x%04X", packet->protocol_type); |
etherealflaim | 0:d494b853ce97 | 44 | main_log.printf(" Type: %d", packet->operation); |
etherealflaim | 0:d494b853ce97 | 45 | if (packet->hardware_type != 0x0001 || packet->protocol_type != 0x0800) return; |
etherealflaim | 0:d494b853ce97 | 46 | |
etherealflaim | 0:d494b853ce97 | 47 | u8 *bytes; |
etherealflaim | 0:d494b853ce97 | 48 | bytes = packet->sender_hardware_address; |
etherealflaim | 0:d494b853ce97 | 49 | 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 | 50 | bytes = packet->target_hardware_address; |
etherealflaim | 0:d494b853ce97 | 51 | 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 | 52 | bytes = packet->sender_protocol_address; |
etherealflaim | 0:d494b853ce97 | 53 | main_log.printf(" Source: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); |
etherealflaim | 0:d494b853ce97 | 54 | bytes = packet->target_protocol_address; |
etherealflaim | 0:d494b853ce97 | 55 | main_log.printf(" Target: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); |
etherealflaim | 0:d494b853ce97 | 56 | } |
etherealflaim | 0:d494b853ce97 | 57 | |
etherealflaim | 0:d494b853ce97 | 58 | #endif |