Dependencies:   NetServices

Dependents:   HvZ

Revision:
0:7e2eb93442e7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/net/ethernet.h	Sun Dec 12 19:34:41 2010 +0000
@@ -0,0 +1,49 @@
+#ifndef ETHERNET_H
+#define ETHERNET_H
+
+#include "net.h"
+
+/**
+  \file ethernet.h
+  \brief Ethernet frame header
+  
+  This file contains the memory map and associated functions for Ethernet frame header
+  creation and deconstruction. 
+*/
+
+/// Ethernet MAC address memory map
+typedef struct {
+  unsigned char octet[6]; ///< Individual octsts of the MAC address
+} Ethernet_MAC;
+
+/// Ethernet II Frame Header Memory map
+typedef struct {
+  /// 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;
+  /// Payload (used for memory mapping; has zero size)
+  unsigned char payload[];
+} Ethernet_FrameHeader;
+
+/// Convert from wire to host or host to wire endian-ness
+inline void fix_endian_ethernet(Ethernet_FrameHeader *header)
+{
+  fix_endian_u16(&header->ethertype);
+}
+
+/// Print out an ethernet packet
+/*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