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.
net/udp.h@2:e8e09adc41fc, 2010-10-12 (annotated)
- Committer:
- etherealflaim
- Date:
- Tue Oct 12 06:10:41 2010 +0000
- Revision:
- 2:e8e09adc41fc
- Parent:
- 0:d494b853ce97
- Child:
- 4:88fc7fa58931
Finished documentation for net/ directory
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:e8e09adc41fc | 6 | /// \file UDP packet |
etherealflaim | 2:e8e09adc41fc | 7 | |
etherealflaim | 0:d494b853ce97 | 8 | #define IPPROTO_UDP 0x11 |
etherealflaim | 2:e8e09adc41fc | 9 | |
etherealflaim | 2:e8e09adc41fc | 10 | /// UDP Packet memory map |
etherealflaim | 0:d494b853ce97 | 11 | typedef struct { |
etherealflaim | 0:d494b853ce97 | 12 | u16 source_port; |
etherealflaim | 0:d494b853ce97 | 13 | u16 destination_port; |
etherealflaim | 0:d494b853ce97 | 14 | u16 length; // entire datagram in bytes |
etherealflaim | 0:d494b853ce97 | 15 | u16 checksum; |
etherealflaim | 0:d494b853ce97 | 16 | u8 data[]; |
etherealflaim | 0:d494b853ce97 | 17 | } UDP_Packet; |
etherealflaim | 0:d494b853ce97 | 18 | |
etherealflaim | 2:e8e09adc41fc | 19 | /// Convert from wire to host or host to wire endianness |
etherealflaim | 0:d494b853ce97 | 20 | inline void fix_endian_udp(UDP_Packet *segment) |
etherealflaim | 0:d494b853ce97 | 21 | { |
etherealflaim | 0:d494b853ce97 | 22 | fix_endian_u16(&segment->source_port); |
etherealflaim | 0:d494b853ce97 | 23 | fix_endian_u16(&segment->destination_port); |
etherealflaim | 0:d494b853ce97 | 24 | fix_endian_u16(&segment->length); |
etherealflaim | 0:d494b853ce97 | 25 | } |
etherealflaim | 0:d494b853ce97 | 26 | |
etherealflaim | 2:e8e09adc41fc | 27 | /// Print the UDP packet |
etherealflaim | 0:d494b853ce97 | 28 | inline void print_udp(UDP_Packet *segment) |
etherealflaim | 0:d494b853ce97 | 29 | { |
etherealflaim | 0:d494b853ce97 | 30 | main_log.printf("UDP Packet:"); |
etherealflaim | 0:d494b853ce97 | 31 | main_log.printf(" Source: PORT %d", segment->source_port); |
etherealflaim | 0:d494b853ce97 | 32 | main_log.printf(" Dest: PORT %d", segment->destination_port); |
etherealflaim | 0:d494b853ce97 | 33 | main_log.printf(" Length: %d", segment->length); |
etherealflaim | 0:d494b853ce97 | 34 | } |
etherealflaim | 0:d494b853ce97 | 35 | |
etherealflaim | 0:d494b853ce97 | 36 | #endif |