25 #define TCP_STATE_CLOSED (0) 26 #define TCP_STATE_LISTEN (1) 27 #define TCP_STATE_SYN_SENT (2) 28 #define TCP_STATE_SYN_RCVD (3) 29 #define TCP_STATE_WAIT_FOR_ACCEPT (4) 30 #define TCP_STATE_ESTABLISHED (5) 31 #define TCP_STATE_CLOSE_WAIT (6) 32 #define TCP_STATE_LAST_ACK (7) 33 #define TCP_STATE_FIN_WAIT_1 (8) 34 #define TCP_STATE_FIN_WAIT_2 (9) 35 #define TCP_STATE_CLOSING (10) 36 #define TCP_STATE_TIME_WAIT (11) 47 #define TCP_ERR_NORMAL (0) 48 #define TCP_ERR_TIMEOUT (-1) 49 #define TCP_ERR_NOCON (-2) 50 #define TCP_ERR_CLOSING (-3) 51 #define TCP_ERR_NOSUCH_SOCKET (-4) 52 #define TCP_ERR_NONE_AVAIL (-5) 53 #define TCP_ERR_CON_RESET (-6) 54 #define TCP_ERR_CON_ABORT (-7) 58 #define INADDR_ANY4 IPADDR4::NullIP() 61 #define INADDR_ANY IPADDR6::NullIP() 63 #define INADDR_ANY INADDR_ANY4 90 int listen4(IPADDR4 addr, uint16_t port, uint8_t maxpend = 5);
124 int accept4(
int listening_socket, IPADDR4 *address, uint16_t *port, uint16_t timeout);
153 int listen6(
const IPADDR6 &addr, uint16_t port, uint8_t maxpend = 5);
155 inline int listen(
const IPADDR6 &addr, uint16_t port, uint8_t maxpend = 5)
157 return listen6(addr, port, maxpend);
192 int accept6(
int listening_socket,
IPADDR6 *address, uint16_t *port, uint16_t timeout);
194 inline int accept(
int listening_socket,
IPADDR6 *address, uint16_t *port, uint16_t timeout)
196 return accept6(listening_socket, address, port, timeout);
200 inline int listen(IPADDR4 addr, uint16_t port, uint8_t maxpend = 5)
202 return listen4(addr, port, maxpend);
204 inline int accept(
int listening_socket, IPADDR4 *address, uint16_t *port, uint16_t timeout)
206 return accept4(listening_socket, address, port, timeout);
233 int connect4wlocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout);
234 int connect4wlocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout, IPADDR4 interfaceIpAddress);
235 inline int connect4(IPADDR4 ipAddress, uint16_t remotePort, uint32_t timeout)
237 return connect4wlocal(ipAddress, 0, remotePort, timeout);
240 inline int connect4wlocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort,
const TickTimeout &timeout)
242 return connect4wlocal(ipAddress, localPort, remotePort, timeout.
val());
246 return connect4wlocal(ipAddress, 0, remotePort, timeout.
val());
273 inline int connect4(IPADDR4 ipAddress, uint16_t remotePort, uint32_t timeout, IPADDR4 interfaceIpAddress)
275 return connect4wlocal(ipAddress, 0, remotePort, timeout, interfaceIpAddress);
279 int connect6wlocal(
const IPADDR6 &ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout);
280 int connect6wlocal(
const IPADDR6 &ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout,
const IPADDR6 &interfaceIpAddress);
281 inline int connect6(
const IPADDR6 &ipAddress, uint16_t remotePort, uint32_t timeout)
283 return connect6wlocal(ipAddress, 0, remotePort, timeout);
310 return connect6wlocal(ipAddress, 0, remotePort, timeout, interfaceIpAddress);
313 inline int connectwlocal(
const IPADDR6 &ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout)
315 return connect6wlocal(ipAddress, localPort, remotePort, timeout);
317 inline int connectwlocal(
const IPADDR6 &ipAddress,
321 const IPADDR6 &interfaceIpAddress)
323 return connect6wlocal(ipAddress, localPort, remotePort, timeout, interfaceIpAddress);
325 inline int connect(
const IPADDR6 &ipAddress, uint16_t remotePort, uint32_t timeout)
327 return connect6(ipAddress, remotePort, timeout);
329 inline int connect(
const IPADDR6 &ipAddress, uint16_t remotePort, uint32_t timeout,
const IPADDR6 &interfaceIpAddress)
331 return connect6(ipAddress, remotePort, timeout, interfaceIpAddress);
334 inline int connect(IPADDR4 ipAddress, uint16_t remotePort, uint32_t timeout)
336 return connect4(ipAddress, remotePort, timeout);
338 inline int connect(IPADDR4 ipAddress, uint16_t remotePort, uint32_t timeout, IPADDR4 interfaceIpAddress)
340 return connect4(ipAddress, remotePort, timeout, interfaceIpAddress);
342 inline int connectwlocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout)
344 return connect4wlocal(ipAddress, localPort, remotePort, timeout);
346 inline int connectwlocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout, IPADDR4 interfaceIpAddress)
348 return connect4wlocal(ipAddress, localPort, remotePort, timeout, interfaceIpAddress);
365 int NoBlockConnect4wLocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, IPADDR4 interfaceIpAddress = IPADDR4::NullIP());
387 inline int NoBlockConnect4(IPADDR4 ipAddress, uint16_t remotePort, IPADDR4 interfaceIpAddress = IPADDR4::NullIP())
389 return NoBlockConnect4wLocal(ipAddress, 0, remotePort, interfaceIpAddress);
392 int NoBlockConnect6wLocal(
const IPADDR6 &ipAddress, uint16_t localPort, uint16_t remotePort,
const IPADDR6 &interfaceIpAddress);
416 return NoBlockConnect6wLocal(ipAddress, 0, remotePort, interfaceIpAddress);
421 return NoBlockConnect6wLocal(ipAddress, 0, remotePort, interfaceIpAddress);
424 inline int NoBlockConnectwLocal(IPADDR4 ipAddress, uint16_t localPort, uint16_t remotePort, IPADDR4 interfaceIpAddress = IPADDR4::NullIP())
426 return NoBlockConnect4wLocal(ipAddress, 0, remotePort, interfaceIpAddress);
428 inline int NoBlockConnect(IPADDR4 ipAddress, uint16_t remotePort, IPADDR4 interfaceIpAddress = IPADDR4::NullIP())
430 return NoBlockConnect4wLocal(ipAddress, 0, remotePort, interfaceIpAddress);
434 int getsocketerror(
int fd);
467 bool bRemoteAddrIsIpV6();
468 bool bLocalAddrIsIpV6();
498 inline IPADDR6 GetSocketRemoteAddr(
int fd)
502 inline IPADDR6 GetSocketLocalAddr(
int fd)
507 inline IPADDR4 GetSocketRemoteAddr(
int fd)
511 inline IPADDR4 GetSocketLocalAddr(
int fd)
625 uint8_t SetOutOfOrderbuffers(
int fd, uint8_t max);
627 #if defined MULTIHOME || defined AUTOIP 629 int connectvia4(IPADDR4 addr, uint16_t localport, uint16_t remoteport, uint32_t timeout, IPADDR4 ipa);
630 int NoBlockconnectvia4(IPADDR4 addr, uint16_t localport, uint16_t remoteport, IPADDR4 ipa);
633 int connectvia6(
const IPADDR6 &addr, uint16_t localport, uint16_t remoteport, uint32_t timeout,
const IPADDR6 &ipa);
634 inline int connectvia(
const IPADDR6 &addr, uint16_t localport, uint16_t remoteport, uint32_t timeout,
const IPADDR6 &ipa)
636 return connectvia6(addr, localport, remoteport, timeout, ipa);
639 int NoBlockconnectvia6(IPADDR4 addr, uint16_t localport, uint16_t remoteport, IPADDR4 ipa);
640 inline int NoBlockconnectvia(IPADDR4 addr, uint16_t localport, uint16_t remoteport, IPADDR4 ipa)
642 return NoBlockconnectvia6(addr, localport, remoteport, ipa);
646 inline int connectvia(IPADDR4 addr, uint16_t localport, uint16_t remoteport, uint32_t timeout, IPADDR4 ipa)
648 return connectvia4(addr, localport, remoteport, timeout, ipa);
650 inline int NoBlockconnectvia(IPADDR4 addr, uint16_t localport, uint16_t remoteport, IPADDR4 ipa)
652 return NoBlockconnectvia4(addr, localport, remoteport, ipa);
703 int setsocketackbuffers(
int fd, uint8_t val);
704 int SetSocketRxBuffers(
int fd,
int n);
705 int SetSocketTxBuffers(
int fd,
int n);
707 int abortsocket(
int fd);
708 int SockReadWithTimeout(
int fd,
char *buf,
int nbytes, uint32_t timeout);
724 void EnableTcpDebug(uint16_t dbFlags);
733 beuint32_t SeqNumber;
734 beuint32_t AckNumber;
743 typedef TCPPKT *PTCPPKT;
752 inline PTCPPKT GetTcpPkt(PIPPKT pIp)
755 if (pIp->bVerHdrLen == 0x45) {
return (PTCPPKT)pIp->DATA; }
756 return (PTCPPKT)(pIp->DATA + (((pIp->bVerHdrLen & 0XF) * 4) - 20));
759 inline PTCPPKT GetTcpPkt(PoolPtr p)
761 return GetTcpPkt(GetIpPkt(p));
763 inline PTCPPKT GetTcpPkt(PEFRAME pFrame)
765 return GetTcpPkt(GetIpPkt(pFrame));
768 inline PTCPPKT GetInitTcpPkt4(PIPPKT pIp)
770 pIp->bVerHdrLen = 0x45;
771 return (PTCPPKT)pIp->DATA;
774 inline PTCPPKT GetInitTcpPkt4(PoolPtr p)
776 return GetInitTcpPkt4(GetIpPkt(p));
780 typedef void(tcp_data_handler)(
int fd, puint8_t data, uint16_t len);
781 void RegisterDataProcessor(
int fd, tcp_data_handler *pdh);
787 void process_tcp4(PoolPtr pp, PIPPKT pIP, uint16_t csum);
790 void EnableTcpDebug(uint16_t);
791 void DumpTcpPacket(PIPPKT pIP);
827 uint16_t TcpGetRxBufferSpaceUsed(
int fd);
843 uint16_t TcpGetTxBufferAvailSpace(
int fd);
862 BOOL TcpAllDataAcked(
int socket);
881 BOOL WaitForSocketFlush(
int fd, uint32_t ticks);
898 typedef void(tcp_notify_handler)(
int tcpFd);
899 void RegisterTCPReadNotify(
int tcpFd, tcp_notify_handler *notifyHandler);
900 void RegisterTCPWriteNotify(
int tcpFd, tcp_notify_handler *notifyHandler);
903 void TCPAssociateExtraData(
int tcpFd,
void *pData);
904 void *TCPGetExtraData(
int tcpFd);
908 #error Got to pick an IP version uint16_t GetSocketRemotePort(int fd)
Returns the port number of the remote host associated with the connection.
Definition: tcp.cpp:2017
static IPADDR6 NullIP()
Return a null IPADDR6 object.
Definition: ipv6_addr.cpp:334
int getsockoption(int fd)
Returns the options for the specified TCP socket.
Definition: tcp.cpp:3008
int connect6(const IPADDR6 &ipAddress, uint16_t remotePort, uint32_t timeout, const IPADDR6 &interfaceIpAddress)
Connect to a remote IPv6 host.
Definition: tcp.h:308
int GetTcpRtxCount(int fd)
Returns the number of re-transmits that have occured on the specified connection. ...
Definition: tcp.cpp:4231
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
uint8_t TcpGetSocketState(int fd)
Return the current state of a TCP socket.
Definition: tcp.cpp:4436
uint16_t GetSocketLocalPort(int fd)
Returns the local port number associated with the connection.
Definition: tcp.cpp:2025
TickTimeouts are used to facilitate sequential function calls with timeout parameters that need to in...
Definition: nbrtos.h:112
int connect4(IPADDR4 ipAddress, uint16_t remotePort, uint32_t timeout, IPADDR4 interfaceIpAddress)
Connect to a remote IPv4 host.
Definition: tcp.h:273
int setsockoption(int fd, int option)
Set TCP socket options.
Definition: tcp.cpp:2999
int clrsockoption(int fd, int option)
Clear TCP socket options.
Definition: tcp.cpp:3016
char SocketPeek(int fd)
Returns the next char that would be read, 0 if no data.
Definition: tcp.cpp:3065
IPADDR6 GetSocketRemoteAddr6(int fd)
Returns the IPv6 address of the remote host associated with the specified file descriptor.
Definition: tcp.cpp:1997
int NoBlockConnect6(const IPADDR6 &ipAddress, uint16_t remotePort, const IPADDR6 &interfaceIpAddress)
Create a file descriptior and return immediately, does not wait for connection to complete...
Definition: tcp.h:414
int listen4(IPADDR4 addr, uint16_t port, uint8_t maxpend=5)
Listen for incoming IPv4 connections.
Definition: tcp.cpp:1000
int listen6(const IPADDR6 &addr, uint16_t port, uint8_t maxpend=5)
Listen for incoming IPv6 connections.
Definition: tcp.cpp:1034
uint32_t TcpGetLastRxInterval(int fd)
Returns the number of system Time Ticks since the last packet was received. This is the difference be...
Definition: tcp.cpp:4466
uint32_t val() const
Get the timeout duration to be passed to a function utilizing timeout ticks.
Definition: nbrtos.h:153
int accept4(int listening_socket, IPADDR4 *address, uint16_t *port, uint16_t timeout)
Accept an incoming IPv4 connection from a listening socket.
Definition: tcp.cpp:1151
IPADDR4 GetSocketRemoteAddr4(int fd)
Returns the IPv4 address of the remote host associated with the specified file descriptor.
Definition: tcp.cpp:1984
#define NULL
Definition: nm_bsp.h:76
int TcpGetSocketInterface(int fd)
Return the network interface asociated with a TCP socket.
Definition: tcp.cpp:4942
uint32_t TcpGetLastRxTime(int fd)
Returns the value of system Time Ticks when the last packet was received. Used for the TCP Keep Alive...
Definition: tcp.cpp:4268
void TcpSendKeepAlive(int fd)
Send a TCP keep alive packet to a remote host.
Definition: tcp.cpp:4276
IPADDR4 GetSocketLocalAddr4(int fd)
Returns the IPv4 address of the local interface associated with the connection.
Definition: tcp.cpp:1948
int accept6(int listening_socket, IPADDR6 *address, uint16_t *port, uint16_t timeout)
Accept an incoming IPv6 connection from a listening socket.
Definition: tcp.cpp:1070
IPADDR6 GetSocketLocalAddr6(int fd)
Returns the IPv6 address of the local interface associated with the connection.
Definition: tcp.cpp:2006
int NoBlockConnect4(IPADDR4 ipAddress, uint16_t remotePort, IPADDR4 interfaceIpAddress=IPADDR4::NullIP())
Create a file descriptior and return immediately, does not wait for connection to complete...
Definition: tcp.h:387