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.
Diff: net/tcp.h
- Revision:
- 2:e8e09adc41fc
- Parent:
- 0:d494b853ce97
- Child:
- 3:c32d9660b888
--- a/net/tcp.h Tue Oct 12 05:54:52 2010 +0000 +++ b/net/tcp.h Tue Oct 12 06:10:41 2010 +0000 @@ -3,32 +3,38 @@ #include "net.h" +/// \file TCP Segment + #define IPPROTO_TCP 0x06 + +/// TCP Segment Memory Map typedef struct { - u16 source_port; - u16 destination_port; - u32 sequence_number; - u32 acknowledge_number; + u16 source_port; ///< Source port (1-65535) + u16 destination_port; ///< Destination port (1-65535) + u32 sequence_number; ///< TCP Sequence number (initial one if SYN set) + u32 acknowledge_number; ///< TCP Acknowledge number (valid if ACK set) - unsigned data_offset_bytes_div4:4; - unsigned unused_0:4; + unsigned data_offset_bytes_div4:4; ///< Length of this header (20) divided by 4 (should be 5) + unsigned unused_0:4; ///< Unused, should be zero - unsigned fin:1; // connection FINished (no more data from sender) - unsigned syn:1; // SYNchronize sequence numbers - unsigned rst:1; // ReSeT the connection - unsigned psh:1; // PuSH to receiving application - unsigned ack:1; // ACKnowledge fiend is significant - unsigned urg:1; // URGent field is significant - unsigned ece:1; // ECn Echo - unsigned cwr:1; // Congestion Window Reduced + unsigned fin:1; ///< connection FINished (no more data from sender) + unsigned syn:1; ///< SYNchronize sequence numbers + unsigned rst:1; ///< ReSeT the connection + unsigned psh:1; ///< PuSH to receiving application + unsigned ack:1; ///< ACKnowledge fiend is significant + unsigned urg:1; ///< URGent field is significant + unsigned ece:1; ///< ECn Echo + unsigned cwr:1; ///< Congestion Window Reduced - u16 window_size; - u16 checksum; - u16 urgent_pointer; - // Options (unsupported) + u16 window_size; ///< TCP Maxumum window size (8192 is good) + u16 checksum; ///< TCP checksum (computed with pseudo header) + u16 urgent_pointer; ///< Urgent pointer (valid if URG set) + + /// Memory map for data if no options are set unsigned char data[]; } TCP_SegmentHeader; +/// Convert from wire to host or host to wire endianness inline void fix_endian_tcp(TCP_SegmentHeader *segment) { segment->unused_0 ^= segment->data_offset_bytes_div4; @@ -43,6 +49,7 @@ fix_endian_u32(&segment->acknowledge_number); } +/// Print the TCP segment header inline void print_tcp(TCP_SegmentHeader *segment) { main_log.printf("TCP Segment:"); @@ -61,6 +68,7 @@ if (segment->fin) main_log.printf(" Flag: FIN"); } +/// Compute the pseudo header checksum with the given source, destination, and length inline u16 pseudo_header_checksum(IP_Address source, IP_Address destination, u16 length) { struct {