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 05:54:52 2010 +0000
Revision:
1:63d4ff534d65
Parent:
0:d494b853ce97
Child:
2:e8e09adc41fc
Added some documentation

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