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 06:48:59 2010 +0000
Revision:
8:1c1f6ce348c6
Parent:
6:66c4cd9073aa
Documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
etherealflaim 0:d494b853ce97 1 #ifndef UDP_H
etherealflaim 0:d494b853ce97 2 #define UDP_H
etherealflaim 0:d494b853ce97 3
etherealflaim 0:d494b853ce97 4 #include "net.h"
etherealflaim 0:d494b853ce97 5
etherealflaim 6:66c4cd9073aa 6 /**
etherealflaim 6:66c4cd9073aa 7 \file udp.h
etherealflaim 6:66c4cd9073aa 8 \brief UDP packet
etherealflaim 6:66c4cd9073aa 9
etherealflaim 6:66c4cd9073aa 10 This file contains the memory map and associated functions for UDP packet
etherealflaim 6:66c4cd9073aa 11 creation and deconstruction.
etherealflaim 6:66c4cd9073aa 12 */
etherealflaim 2:e8e09adc41fc 13
etherealflaim 0:d494b853ce97 14 #define IPPROTO_UDP 0x11
etherealflaim 2:e8e09adc41fc 15
etherealflaim 2:e8e09adc41fc 16 /// UDP Packet memory map
etherealflaim 0:d494b853ce97 17 typedef struct {
etherealflaim 4:88fc7fa58931 18 u16 source_port; ///< Source port (1-65535)
etherealflaim 4:88fc7fa58931 19 u16 destination_port; ///< Destination port (1-65535)
etherealflaim 4:88fc7fa58931 20 u16 length; ///< Entire datagram size in bytes
etherealflaim 4:88fc7fa58931 21 u16 checksum; ///< Checksum
etherealflaim 4:88fc7fa58931 22 u8 data[]; ///< Data memory map
etherealflaim 0:d494b853ce97 23 } UDP_Packet;
etherealflaim 0:d494b853ce97 24
etherealflaim 2:e8e09adc41fc 25 /// Convert from wire to host or host to wire endianness
etherealflaim 0:d494b853ce97 26 inline void fix_endian_udp(UDP_Packet *segment)
etherealflaim 0:d494b853ce97 27 {
etherealflaim 0:d494b853ce97 28 fix_endian_u16(&segment->source_port);
etherealflaim 0:d494b853ce97 29 fix_endian_u16(&segment->destination_port);
etherealflaim 0:d494b853ce97 30 fix_endian_u16(&segment->length);
etherealflaim 0:d494b853ce97 31 }
etherealflaim 0:d494b853ce97 32
etherealflaim 2:e8e09adc41fc 33 /// Print the UDP packet
etherealflaim 0:d494b853ce97 34 inline void print_udp(UDP_Packet *segment)
etherealflaim 0:d494b853ce97 35 {
etherealflaim 0:d494b853ce97 36 main_log.printf("UDP Packet:");
etherealflaim 0:d494b853ce97 37 main_log.printf(" Source: PORT %d", segment->source_port);
etherealflaim 0:d494b853ce97 38 main_log.printf(" Dest: PORT %d", segment->destination_port);
etherealflaim 0:d494b853ce97 39 main_log.printf(" Length: %d", segment->length);
etherealflaim 0:d494b853ce97 40 }
etherealflaim 0:d494b853ce97 41
etherealflaim 0:d494b853ce97 42 #endif