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.
ethernet.h
00001 #ifndef ETHERNET_H 00002 #define ETHERNET_H 00003 00004 #include "net.h" 00005 00006 /** 00007 \file ethernet.h 00008 \brief Ethernet frame header 00009 00010 This file contains the memory map and associated functions for Ethernet frame header 00011 creation and deconstruction. 00012 */ 00013 00014 /// Ethernet MAC address memory map 00015 typedef struct { 00016 unsigned char octet[6]; ///< Individual octsts of the MAC address 00017 } Ethernet_MAC; 00018 00019 /// Ethernet II Frame Header Memory map 00020 typedef struct { 00021 /// Destination MAC address (6 octets) 00022 Ethernet_MAC destination; 00023 /// Source MAC address (6 octets) 00024 Ethernet_MAC source; 00025 // (optional) VLAN Tag (unsupported) 00026 /// Ethernet type or length (only <0x600 or 0x0800 IPv4 supported) 00027 u16 ethertype; 00028 /// Payload (used for memory mapping; has zero size) 00029 unsigned char payload[]; 00030 } Ethernet_FrameHeader; 00031 00032 /// Convert from wire to host or host to wire endian-ness 00033 inline void fix_endian_ethernet(Ethernet_FrameHeader *header) 00034 { 00035 fix_endian_u16(&header->ethertype); 00036 } 00037 00038 /// Print out an ethernet packet 00039 inline void print_ethernet(Ethernet_FrameHeader *frame) 00040 { 00041 main_log.printf("Ethernet frame:"); 00042 u8 *src = frame->source.octet; 00043 u8 *dst = frame->destination.octet; 00044 main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", src[6], src[7], src[8], src[9], src[10], src[11]); 00045 main_log.printf(" Dest: MAC - %02X:%02X:%02X:%02X:%02X:%02X", dst[0], dst[1], dst[2], dst[3], dst[4], dst[5]); 00046 main_log.printf(" Ethertype: 0x%04X", frame->ethertype); 00047 } 00048 00049 #endif
Generated on Tue Jul 12 2022 11:59:40 by 1.7.2