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.

Dependencies:   mbed

Committer:
etherealflaim
Date:
Tue Oct 12 06:10:41 2010 +0000
Revision:
2:e8e09adc41fc
Parent:
1:63d4ff534d65
Child:
3:c32d9660b888
Finished documentation for net/ directory

Who changed what in which revision?

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