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.

Dependencies:   mbed

Revision:
0:d494b853ce97
Child:
2:e8e09adc41fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/net/ethernet.h	Tue Oct 12 05:32:59 2010 +0000
@@ -0,0 +1,37 @@
+#ifndef ETHERNET_H
+#define ETHERNET_H
+
+#include "net.h"
+
+typedef struct {
+  unsigned char octet[6];
+} Ethernet_MAC;
+
+typedef struct {
+  // In the Ethernet II Framing Standard:
+  // Destination MAC address (6 octets)
+  Ethernet_MAC destination;
+  // Source MAC address (6 octets)
+  Ethernet_MAC source;
+  // (optional) VLAN Tag (unsupported)
+  // Ethernet type or length (only <0x600 or 0x0800 IPv4 supported)
+  u16 ethertype;
+  unsigned char payload[];
+} Ethernet_FrameHeader;
+
+inline void fix_endian_ethernet(Ethernet_FrameHeader *header)
+{
+  fix_endian_u16(&header->ethertype);
+}
+
+inline void print_ethernet(Ethernet_FrameHeader *frame)
+{
+  main_log.printf("Ethernet frame:");
+  u8 *src = frame->source.octet;
+  u8 *dst = frame->destination.octet;
+  main_log.printf("  Source:    MAC - %02X:%02X:%02X:%02X:%02X:%02X", src[6], src[7], src[8], src[9], src[10], src[11]);
+  main_log.printf("  Dest:      MAC - %02X:%02X:%02X:%02X:%02X:%02X", dst[0], dst[1], dst[2], dst[3], dst[4], dst[5]);
+  main_log.printf("  Ethertype: 0x%04X", frame->ethertype);
+}
+
+#endif
\ No newline at end of file