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

net/udp.h

Committer:
etherealflaim
Date:
2010-10-12
Revision:
4:88fc7fa58931
Parent:
2:e8e09adc41fc
Child:
6:66c4cd9073aa

File content as of revision 4:88fc7fa58931:

#ifndef UDP_H
#define UDP_H

#include "net.h"

/// \file UDP packet

#define IPPROTO_UDP 0x11

/// UDP Packet memory map
typedef struct {
  u16 source_port;       ///< Source port (1-65535)
  u16 destination_port;  ///< Destination port (1-65535) 
  u16 length;            ///< Entire datagram size in bytes
  u16 checksum;          ///< Checksum
  u8 data[];             ///< Data memory map
} UDP_Packet;

/// Convert from wire to host or host to wire endianness
inline void fix_endian_udp(UDP_Packet *segment)
{
  fix_endian_u16(&segment->source_port);
  fix_endian_u16(&segment->destination_port);
  fix_endian_u16(&segment->length);
}

/// Print the UDP packet
inline void print_udp(UDP_Packet *segment)
{
  main_log.printf("UDP Packet:");
  main_log.printf("  Source:    PORT %d", segment->source_port);
  main_log.printf("  Dest:      PORT %d", segment->destination_port);
  main_log.printf("  Length:    %d", segment->length);
}

#endif