![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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/ethernet.h@6:66c4cd9073aa, 2010-10-12 (annotated)
- Committer:
- etherealflaim
- Date:
- Tue Oct 12 06:46:22 2010 +0000
- Revision:
- 6:66c4cd9073aa
- Parent:
- 3:c32d9660b888
File documentation updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
etherealflaim | 0:d494b853ce97 | 1 | #ifndef ETHERNET_H |
etherealflaim | 0:d494b853ce97 | 2 | #define ETHERNET_H |
etherealflaim | 0:d494b853ce97 | 3 | |
etherealflaim | 0:d494b853ce97 | 4 | #include "net.h" |
etherealflaim | 0:d494b853ce97 | 5 | |
etherealflaim | 6:66c4cd9073aa | 6 | /** |
etherealflaim | 6:66c4cd9073aa | 7 | \file ethernet.h |
etherealflaim | 6:66c4cd9073aa | 8 | \brief Ethernet frame header |
etherealflaim | 6:66c4cd9073aa | 9 | |
etherealflaim | 6:66c4cd9073aa | 10 | This file contains the memory map and associated functions for Ethernet frame header |
etherealflaim | 6:66c4cd9073aa | 11 | creation and deconstruction. |
etherealflaim | 6:66c4cd9073aa | 12 | */ |
etherealflaim | 2:e8e09adc41fc | 13 | |
etherealflaim | 3:c32d9660b888 | 14 | /// Ethernet MAC address memory map |
etherealflaim | 0:d494b853ce97 | 15 | typedef struct { |
etherealflaim | 2:e8e09adc41fc | 16 | unsigned char octet[6]; ///< Individual octsts of the MAC address |
etherealflaim | 0:d494b853ce97 | 17 | } Ethernet_MAC; |
etherealflaim | 0:d494b853ce97 | 18 | |
etherealflaim | 3:c32d9660b888 | 19 | /// Ethernet II Frame Header Memory map |
etherealflaim | 0:d494b853ce97 | 20 | typedef struct { |
etherealflaim | 2:e8e09adc41fc | 21 | /// Destination MAC address (6 octets) |
etherealflaim | 0:d494b853ce97 | 22 | Ethernet_MAC destination; |
etherealflaim | 2:e8e09adc41fc | 23 | /// Source MAC address (6 octets) |
etherealflaim | 0:d494b853ce97 | 24 | Ethernet_MAC source; |
etherealflaim | 0:d494b853ce97 | 25 | // (optional) VLAN Tag (unsupported) |
etherealflaim | 2:e8e09adc41fc | 26 | /// Ethernet type or length (only <0x600 or 0x0800 IPv4 supported) |
etherealflaim | 0:d494b853ce97 | 27 | u16 ethertype; |
etherealflaim | 2:e8e09adc41fc | 28 | /// Payload (used for memory mapping; has zero size) |
etherealflaim | 0:d494b853ce97 | 29 | unsigned char payload[]; |
etherealflaim | 0:d494b853ce97 | 30 | } Ethernet_FrameHeader; |
etherealflaim | 0:d494b853ce97 | 31 | |
etherealflaim | 2:e8e09adc41fc | 32 | /// Convert from wire to host or host to wire endian-ness |
etherealflaim | 0:d494b853ce97 | 33 | inline void fix_endian_ethernet(Ethernet_FrameHeader *header) |
etherealflaim | 0:d494b853ce97 | 34 | { |
etherealflaim | 0:d494b853ce97 | 35 | fix_endian_u16(&header->ethertype); |
etherealflaim | 0:d494b853ce97 | 36 | } |
etherealflaim | 0:d494b853ce97 | 37 | |
etherealflaim | 2:e8e09adc41fc | 38 | /// Print out an ethernet packet |
etherealflaim | 0:d494b853ce97 | 39 | inline void print_ethernet(Ethernet_FrameHeader *frame) |
etherealflaim | 0:d494b853ce97 | 40 | { |
etherealflaim | 0:d494b853ce97 | 41 | main_log.printf("Ethernet frame:"); |
etherealflaim | 0:d494b853ce97 | 42 | u8 *src = frame->source.octet; |
etherealflaim | 0:d494b853ce97 | 43 | u8 *dst = frame->destination.octet; |
etherealflaim | 0:d494b853ce97 | 44 | main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", src[6], src[7], src[8], src[9], src[10], src[11]); |
etherealflaim | 0:d494b853ce97 | 45 | main_log.printf(" Dest: MAC - %02X:%02X:%02X:%02X:%02X:%02X", dst[0], dst[1], dst[2], dst[3], dst[4], dst[5]); |
etherealflaim | 0:d494b853ce97 | 46 | main_log.printf(" Ethertype: 0x%04X", frame->ethertype); |
etherealflaim | 0:d494b853ce97 | 47 | } |
etherealflaim | 0:d494b853ce97 | 48 | |
etherealflaim | 0:d494b853ce97 | 49 | #endif |