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:
2:e8e09adc41fc
Parent:
0:d494b853ce97
Child:
3:c32d9660b888
--- a/net/ip.h	Tue Oct 12 05:54:52 2010 +0000
+++ b/net/ip.h	Tue Oct 12 06:10:41 2010 +0000
@@ -3,51 +3,52 @@
 
 #include "net.h"
 
+/// \file IP Packet
+
 #define ETHERTYPE_IPV4 0x0800
 #define ETHERTYPE_IPV6 0x86DD
 
-/************** IPv4 ***************/
-
+/// IP Address memory map
 typedef struct {
-  unsigned char octet[4];
+  unsigned char octet[4]; ///< Individual address octets
 } IP_Address;
 
-// 0x0800
+/// Memory map of IP Packet - Some may not work (see comments)
 typedef struct {
-  // IP packets are composed of a header and payload. The IPv4 packet header consists of:
-  // 4 bits that contain the version, that specifies if it's an IPv4 or IPv6 packet,
+  /// 4 bits that contain the version, that specifies if it's an IPv4 or IPv6 packet,
   unsigned version:4; // Only 0x4 supported
-  // 4 bits that contain the Internet Header Length which is the length of the header in multiples of 4 bytes (eg. 5 means 20 bytes).
+  /// 4 bits that contain the Internet Header Length which is the length of the header in multiples of 4 bytes (eg. 5 means 20 bytes).
   unsigned header_bytes_div4:4;
-  // 8 bits that contain the Type of Service, also referred to as Quality of Service (QoS), which describes what priority the packet should have,
+  /// 8 bits that contain the Type of Service, also referred to as Quality of Service (QoS), which describes what priority the packet should have,
   unsigned tos:8;
-  // 16 bits that contain the total length of the IP packet (datagram) in bytes,
+  /// 16 bits that contain the total length of the IP packet (datagram) in bytes,
   u16 packet_bytes;
-  // 16 bits that contain an identification tag to help reconstruct the packet from several fragments,
+  /// 16 bits that contain an identification tag to help reconstruct the packet from several fragments,
   u16 fragment_id;
-  // 3 bits that contain a zero, a flag that says whether the packet is allowed to be fragmented or not (DF: Don't fragment), and a flag to state whether more fragments of a packet follow (MF: More Fragments)
+  /// 3 bits that contain a zero, a flag that says whether the packet is allowed to be fragmented or not (DF: Don't fragment), and a flag to state whether more fragments of a packet follow (MF: More Fragments)
   unsigned unused_0:1;
   unsigned dont_fragment:1;
   unsigned more_follow:1;
-  // 13 bits that contain the fragment offset, a field to identify position of fragment within original packet
+  /// 13 bits that contain the fragment offset, a field to identify position of fragment within original packet
   unsigned fragment_offset:13; ////// This and the ones above may not work properly due to endianness
-  // 8 bits that contain the Time to live (TTL) which is the number of hops (router, computer or device along a network) the packet is allowed to pass before it dies (for example, a packet with a TTL of 16 will be allowed to go across 16 routers to get to its destination before it is discarded),
+  /// 8 bits that contain the Time to live (TTL) which is the number of hops (router, computer or device along a network) the packet is allowed to pass before it dies (for example, a packet with a TTL of 16 will be allowed to go across 16 routers to get to its destination before it is discarded),
   unsigned ttl:8;
-  // 8 bits that contain the protocol (TCP, UDP, ICMP, etc...)
-  //   0x01 ICMP
-  //   0x06 TCP
-  //   0x11 UDP
+  /// 8 bits that contain the protocol (TCP, UDP, ICMP, etc...)
+  ///   0x01 ICMP
+  ///   0x06 TCP
+  ///   0x11 UDP
   unsigned protocol:8;
-  // 16 bits that contain the Header Checksum, a number used in error detection,
+  /// 16 bits that contain the Header Checksum, a number used in error detection,
   u16 header_checksum;
-  // 32 bits that contain the source IP address,
+  /// 32 bits that contain the source IP address,
   IP_Address source;
-  // 32 bits that contain the destination address.
+  /// 32 bits that contain the destination address.
   IP_Address destination;
-  // Other flags are unsupported
+  /// Zero-length field for memory mapping the packet data
   unsigned char data[];
 } IP_PacketHeader;
 
+/// Convert from wire to host or host to wire endianness
 inline void fix_endian_ip(IP_PacketHeader *packet)
 {
   packet->version ^= packet->header_bytes_div4;
@@ -58,6 +59,7 @@
   // Don't fix checksums; they are done bitwise
 }
 
+/// Get a constant string of the given IP protocol (e.g. "ICMP", "TCP", "UDP") if known
 inline const char *ipproto2name(u8 proto)
 {
   switch (proto)
@@ -70,6 +72,7 @@
   return "<UNKNOWN>";
 }
 
+/// Print the IP packet
 inline void print_ip(IP_PacketHeader *packet)
 {
   main_log.printf("IPv%d Packet:", packet->version);
@@ -92,6 +95,7 @@
   main_log.printf("  Checksum:  0x%04X", packet->header_checksum);
 }
 
+/// Parse the string (in decimal triple-dot notation) into the IP address structure
 inline void str2ipaddr(const char *ip, IP_Address *addr)
 {
   static short a,b,c,d;