1 /* 2 * Copyright 2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Andrew Galante, haiku.galante@gmail.com 7 */ 8 #ifndef TCP_H 9 #define TCP_H 10 11 12 #include <net_buffer.h> 13 #include <net_datalink.h> 14 #include <net_stack.h> 15 16 #include <util/khash.h> 17 18 #include <sys/socket.h> 19 20 21 typedef enum { 22 CLOSED, 23 LISTEN, 24 SYN_SENT, 25 SYN_RCVD, 26 ESTABLISHED, 27 CLOSE_WAIT, 28 LAST_ACK, 29 FIN_WAIT1, 30 FIN_WAIT2, 31 CLOSING, 32 TIME_WAIT 33 } tcp_state; 34 35 struct tcp_header { 36 uint16 source_port; 37 uint16 destination_port; 38 uint32 sequence_num; 39 uint32 acknowledge_num; 40 struct { 41 #if B_HOST_IS_LENDIAN == 1 42 uint8 reserved : 4; 43 uint8 header_length : 4; 44 #else 45 uint8 header_length : 4; 46 uint8 reserved : 4; 47 #endif 48 }; 49 uint8 flags; 50 uint16 advertised_window; 51 uint16 checksum; 52 uint16 urgent_ptr; 53 }; 54 55 // TCP flag constants 56 #define TCP_FLG_CWR 0x80 // Congestion Window Reduced 57 #define TCP_FLG_ECN 0x40 // Explicit Congestion Notification echo 58 #define TCP_FLG_URG 0x20 // URGent 59 #define TCP_FLG_ACK 0x10 // ACKnowledge 60 #define TCP_FLG_PUS 0x08 // PUSh 61 #define TCP_FLG_RST 0x04 // ReSeT 62 #define TCP_FLG_SYN 0x02 // SYNchronize 63 #define TCP_FLG_FIN 0x01 // FINish 64 65 struct tcp_connection_key { 66 const sockaddr *local; 67 const sockaddr *peer; 68 }; 69 70 71 extern net_domain *gDomain; 72 extern net_address_module_info *gAddressModule; 73 extern net_buffer_module_info *gBufferModule; 74 extern net_datalink_module_info *gDatalinkModule; 75 extern net_stack_module_info *gStackModule; 76 extern hash_table *gConnectionHash; 77 extern benaphore gConnectionLock; 78 79 80 status_t add_tcp_header(net_buffer *buffer, uint16 flags, uint32 sequence, 81 uint32 ack, uint16 advertisedWindow); 82 83 #endif TCP_H 84