test icmp

Dependencies:   mbed

Fork of ethspam by Rolf Meyer

net/udp.h

Committer:
jamessayer
Date:
2015-04-24
Revision:
1:feaa107f56b3

File content as of revision 1:feaa107f56b3:

#ifndef UDP_H
#define UDP_H

#include "net.h"

/**
  \file udp.h
  \brief UDP packet
  
  This file contains the memory map and associated functions for UDP packet
  creation and deconstruction. 
*/

#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)
{
  printf("UDP Packet: \n");
  printf("  Source:    PORT %d \n", segment->source_port);
  printf("  Dest:      PORT %d \n", segment->destination_port);
  printf("  Length:    %d \n", segment->length);
}

#endif