-#define UTCP_INTERNAL
-#include "utcp.h"
-
-#define PREP(l) char pkt[(l) + sizeof struct hdr]; struct hdr *hdr = &pkt;
-
-#define SYN 1
-#define ACK 2
-#define FIN 4
-#define RST 8
-
-struct hdr {
- uint16_t src; // Source port
- uint16_t dst; // Destination port
- uint32_t seq; // Sequence number
- uint32_t ack; // Acknowledgement number
- uint32_t wnd; // Window size
- uint16_t ctl; // Flags (SYN, ACK, FIN, RST)
- uint16_t aux; // other stuff
-};
-
-enum state {
- CLOSED,
- LISTEN,
- SYN_SENT,
- SYN_RECEIVED,
- ESTABLISHED,
- FIN_WAIT_1,
- FIN_WAIT_2,
- CLOSE_WAIT,
- CLOSING,
- LAST_ACK,
- TIME_WAIT
-};
-
-const char *strstate[] = {
- "CLOSED",
- "LISTEN",
- "SYN_SENT",
- "SYN_RECEIVED",
- "ESTABLISHED",
- "FIN_WAIT_1",
- "FIN_WAIT_2",
- "CLOSE_WAIT",
- "CLOSING",
- "LAST_ACK",
- "TIME_WAIT"
-};
-
-struct utcp_connection {
- void *priv;
- struct utcp *utcp;
- bool reapable;
-
- uint16_t src;
- uint16_t dst;
- enum state state;
-
- // The following two structures form the TCB
-
- struct {
- uint32_t una;
- uint32_t nxt;
- uint32_t wnd;
- uint32_t up;
- uint32_t wl1;
- uint32_t wl2;
- uint32_t iss;
- } snd;
-
- struct {
- uint32_t nxt;
- uint32_t wnd;
- uint32_t up;
- uint32_t irs;
- } rcv;
-
- utcp_recv_t recv;
-
- struct timeval conn_timeout;
- struct timeval rtrx_timeout;
-
- char *sndbuf;
- uint32_t sndbufsize;
-};
-
-struct utcp {
- void *priv;
-
- utcp_accept_t accept;
- utcp_pre_accept_t pre_accept;
- utcp_send_t send;
-
- uint16_t mtu;
- int timeout;
-
- struct utcp_connection **connections;
- int nconnections;
- int nallocated;
-};