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

Committer:
etherealflaim
Date:
Tue Oct 12 05:32:59 2010 +0000
Revision:
0:d494b853ce97
Child:
2:e8e09adc41fc
Initial Publish - Slightly unfinished, but usable

Who changed what in which revision?

UserRevisionLine numberNew 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 0:d494b853ce97 6 typedef struct {
etherealflaim 0:d494b853ce97 7 unsigned char octet[6];
etherealflaim 0:d494b853ce97 8 } Ethernet_MAC;
etherealflaim 0:d494b853ce97 9
etherealflaim 0:d494b853ce97 10 typedef struct {
etherealflaim 0:d494b853ce97 11 // In the Ethernet II Framing Standard:
etherealflaim 0:d494b853ce97 12 // Destination MAC address (6 octets)
etherealflaim 0:d494b853ce97 13 Ethernet_MAC destination;
etherealflaim 0:d494b853ce97 14 // Source MAC address (6 octets)
etherealflaim 0:d494b853ce97 15 Ethernet_MAC source;
etherealflaim 0:d494b853ce97 16 // (optional) VLAN Tag (unsupported)
etherealflaim 0:d494b853ce97 17 // Ethernet type or length (only <0x600 or 0x0800 IPv4 supported)
etherealflaim 0:d494b853ce97 18 u16 ethertype;
etherealflaim 0:d494b853ce97 19 unsigned char payload[];
etherealflaim 0:d494b853ce97 20 } Ethernet_FrameHeader;
etherealflaim 0:d494b853ce97 21
etherealflaim 0:d494b853ce97 22 inline void fix_endian_ethernet(Ethernet_FrameHeader *header)
etherealflaim 0:d494b853ce97 23 {
etherealflaim 0:d494b853ce97 24 fix_endian_u16(&header->ethertype);
etherealflaim 0:d494b853ce97 25 }
etherealflaim 0:d494b853ce97 26
etherealflaim 0:d494b853ce97 27 inline void print_ethernet(Ethernet_FrameHeader *frame)
etherealflaim 0:d494b853ce97 28 {
etherealflaim 0:d494b853ce97 29 main_log.printf("Ethernet frame:");
etherealflaim 0:d494b853ce97 30 u8 *src = frame->source.octet;
etherealflaim 0:d494b853ce97 31 u8 *dst = frame->destination.octet;
etherealflaim 0:d494b853ce97 32 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 33 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 34 main_log.printf(" Ethertype: 0x%04X", frame->ethertype);
etherealflaim 0:d494b853ce97 35 }
etherealflaim 0:d494b853ce97 36
etherealflaim 0:d494b853ce97 37 #endif