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
- Committer:
- etherealflaim
- Date:
- 2010-10-12
- Revision:
- 8:1c1f6ce348c6
- Parent:
- 5:c56386b9fc33
File content as of revision 8:1c1f6ce348c6:
#ifndef ARP_H #define ARP_H #include "net.h" /** \file \brief ARP packet This file contains the memory map and associated functions for ARP packet creation and deconstruction. */ #define ETHERTYPE_ARP 0x0806 /// ARP Packet memory map typedef struct { u16 hardware_type; ///< 0x0001 for ethernet u16 protocol_type; ///< 0x0800 for IPv4 u8 hardware_length; ///< Bytes. Ethernet is 6 u8 protocol_length; ///< Bytes. IPv4 is 4 u16 operation; ///< Operation. 1 for request, 2 for reply or announce // The following are only valid for IPv4 over Ethernet u8 sender_hardware_address[6]; ///< Generator of the request or reply u8 sender_protocol_address[4]; ///< All zeroes for an ARP probe u8 target_hardware_address[6]; ///< Announce - same as SHA u8 target_protocol_address[4]; ///< Announce - Same as TPA } ARP_Packet; /// Convert from wire to host or host to wire endianness inline void fix_endian_arp(ARP_Packet *packet) { fix_endian_u16(&packet->hardware_type); fix_endian_u16(&packet->protocol_type); fix_endian_u16(&packet->operation); } /// Print the ARP packet inline void print_arp(ARP_Packet *packet) { main_log.printf("ARP Packet:"); main_log.printf(" Hardware: 0x%04X", packet->hardware_type); main_log.printf(" Protocol: 0x%04X", packet->protocol_type); main_log.printf(" Type: %d", packet->operation); if (packet->hardware_type != 0x0001 || packet->protocol_type != 0x0800) return; u8 *bytes; bytes = packet->sender_hardware_address; main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); bytes = packet->target_hardware_address; main_log.printf(" Target: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); bytes = packet->sender_protocol_address; main_log.printf(" Source: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); bytes = packet->target_protocol_address; main_log.printf(" Target: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); } #endif