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.
arp.h
00001 #ifndef ARP_H 00002 #define ARP_H 00003 00004 #include "net.h" 00005 00006 /** 00007 \file 00008 \brief ARP packet 00009 00010 This file contains the memory map and associated functions for ARP packet 00011 creation and deconstruction. 00012 */ 00013 00014 #define ETHERTYPE_ARP 0x0806 00015 00016 /// ARP Packet memory map 00017 typedef struct { 00018 u16 hardware_type; ///< 0x0001 for ethernet 00019 u16 protocol_type; ///< 0x0800 for IPv4 00020 u8 hardware_length; ///< Bytes. Ethernet is 6 00021 u8 protocol_length; ///< Bytes. IPv4 is 4 00022 u16 operation; ///< Operation. 1 for request, 2 for reply or announce 00023 // The following are only valid for IPv4 over Ethernet 00024 u8 sender_hardware_address[6]; ///< Generator of the request or reply 00025 u8 sender_protocol_address[4]; ///< All zeroes for an ARP probe 00026 u8 target_hardware_address[6]; ///< Announce - same as SHA 00027 u8 target_protocol_address[4]; ///< Announce - Same as TPA 00028 } ARP_Packet; 00029 00030 /// Convert from wire to host or host to wire endianness 00031 inline void fix_endian_arp(ARP_Packet *packet) 00032 { 00033 fix_endian_u16(&packet->hardware_type); 00034 fix_endian_u16(&packet->protocol_type); 00035 fix_endian_u16(&packet->operation); 00036 } 00037 00038 /// Print the ARP packet 00039 inline void print_arp(ARP_Packet *packet) 00040 { 00041 main_log.printf("ARP Packet:"); 00042 main_log.printf(" Hardware: 0x%04X", packet->hardware_type); 00043 main_log.printf(" Protocol: 0x%04X", packet->protocol_type); 00044 main_log.printf(" Type: %d", packet->operation); 00045 if (packet->hardware_type != 0x0001 || packet->protocol_type != 0x0800) return; 00046 00047 u8 *bytes; 00048 bytes = packet->sender_hardware_address; 00049 main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); 00050 bytes = packet->target_hardware_address; 00051 main_log.printf(" Target: MAC - %02X:%02X:%02X:%02X:%02X:%02X", bytes[0],bytes[1],bytes[2],bytes[3],bytes[4],bytes[5]); 00052 bytes = packet->sender_protocol_address; 00053 main_log.printf(" Source: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); 00054 bytes = packet->target_protocol_address; 00055 main_log.printf(" Target: IP - %03d.%03d.%03d.%03d", bytes[0], bytes[1], bytes[2], bytes[3]); 00056 } 00057 00058 #endif
Generated on Tue Jul 12 2022 11:59:40 by 1.7.2