Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

tcp.h

Go to the documentation of this file.
00001 /*!     \file include/net/tcp.h
00002  *      \brief Header for the TCP (Transmition Control Protocol).
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date 2003-10-27
00005  *      \note Copyright (C) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef TCP_H
00009 #define TCP_H
00010 
00011 /** \ingroup Network
00012  *  \defgroup NetTCP TCP (Transmition Control Protocol) layer
00013  *  The TCP (Transmition Control Protocol) layer.
00014  *  @{
00015  */
00016 
00017 //! TCP connection closed state.
00018 #define TCP_CLOSED      0
00019 //! TCP SYN received state.
00020 #define TCP_SYN_RCVD    1
00021 //! TCP SYN sent state.
00022 #define TCP_SYN_SENT    2
00023 //! TCP connection established state.
00024 #define TCP_ESTABLISHED 3
00025 //! TCP closing state.
00026 #define TCP_CLOSING     4
00027 
00028 //! A socket structure.
00029 typedef struct
00030 {
00031         //! IP source address (in network format).
00032         in_addr_t ip_src;
00033         //! Source port.
00034         uint16_t port_src;
00035         //! IP destination address (in network format).
00036         in_addr_t ip_dst;
00037         //! Destination port.
00038         uint16_t port_dst;
00039 } socket_t;
00040 
00041 //! A TCP connection states machine structure.
00042 typedef struct
00043 {
00044         // The state of the connection.
00045         int state;
00046         //! The socket used in the connection.
00047         socket_t socket;
00048         //! The current sequence number.
00049         int seq_num;
00050 } tcp_state_t;
00051 
00052 //! TCP packet structure.
00053 typedef struct tcp
00054 {
00055         //! Source port.
00056         uint16_t tcp_src;
00057         //! Destination port.
00058         uint16_t tcp_dst;
00059 
00060         //! Sequence number.
00061         uint32_t tcp_seq_num;
00062         //! ACK number.
00063         uint32_t tcp_ack_num;
00064 
00065 #if __BYTE_ORDER__ == __LITTLE_ENDIAN__
00066         //! Reserved (bit 0..3).
00067         uint8_t tcp_res1:4;
00068         //! Header length.
00069         uint8_t tcp_hdr_len:4;
00070         //! FIN flag.
00071         uint8_t tcp_fin:1;
00072         //! SYN flag.
00073         uint8_t tcp_syn:1;
00074         //! RST flag.
00075         uint8_t tcp_rst:1;
00076         //! PSH flag.
00077         uint8_t tcp_psh:1;
00078         //! ACK flag.
00079         uint8_t tcp_ack:1;
00080         //! URG flag.
00081         uint8_t tcp_urg:1;
00082         //! Reserved (bit 4..6).
00083         uint8_t tcp_res2:2;
00084 #else
00085         //! Header length.
00086         uint8_t tcp_hdr_len:4;
00087         //! Reserved.
00088         uint8_t tcp_res:6;
00089         //! URG flag.
00090         uint8_t tcp_urg:1;
00091         //! ACK flag.
00092         uint8_t tcp_ack:1;
00093         //! PSH flag.
00094         uint8_t tcp_psh:1;
00095         //! RST flag.
00096         uint8_t tcp_rst:1;
00097         //! SYN flag.
00098         uint8_t tcp_syn:1;
00099         //! FIN flag.
00100         uint8_t tcp_fin:1;
00101 #endif
00102         //! Window size.
00103         uint16_t tcp_win_size;
00104         //! TCP checksum.
00105         uint16_t tcp_chk;
00106         //! Urgent pointer.
00107         uint16_t tcp_urg_ptr;
00108         
00109 } __attribute__ ((packed)) tcp_t;
00110 
00111 // --- Prototypes ----------------------------------------------------- //
00112 
00113 void to_tcp_layer(tcp_t *packet, size_t len, in_addr_t ip_src, in_addr_t ip_dst);
00114 int tcp_module_init();
00115 int tcp_module_close();
00116 
00117 /** @} */ // end of NetTCP
00118 
00119 #endif

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18