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:
- 0:d494b853ce97
- Child:
- 1:63d4ff534d65
File content as of revision 0:d494b853ce97:
#ifndef ARP_H #define ARP_H #include "net.h" #define ETHERTYPE_ARP 0x0806 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; 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); } 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