36#define Socket struct _Socket
45#ifndef SOCKET_MAX_COUNT
46 #define SOCKET_MAX_COUNT 16
47#elif (SOCKET_MAX_COUNT < 1)
48 #error SOCKET_MAX_COUNT parameter is not valid
52#ifndef SOCKET_MAX_MULTICAST_GROUPS
53 #define SOCKET_MAX_MULTICAST_GROUPS 1
54#elif (SOCKET_MAX_MULTICAST_GROUPS < 1)
55 #error SOCKET_MAX_MULTICAST_GROUPS parameter is not valid
59#ifndef SOCKET_EPHEMERAL_PORT_MIN
60 #define SOCKET_EPHEMERAL_PORT_MIN 49152
61#elif (SOCKET_EPHEMERAL_PORT_MIN < 1024)
62 #error SOCKET_EPHEMERAL_PORT_MIN parameter is not valid
66#ifndef SOCKET_EPHEMERAL_PORT_MAX
67 #define SOCKET_EPHEMERAL_PORT_MAX 65535
68#elif (SOCKET_EPHEMERAL_PORT_MAX <= SOCKET_EPHEMERAL_PORT_MIN || SOCKET_EPHEMERAL_PORT_MAX > 65535)
69 #error SOCKET_EPHEMERAL_PORT_MAX parameter is not valid
84 SOCKET_TYPE_UNUSED = 0,
85 SOCKET_TYPE_STREAM = 1,
86 SOCKET_TYPE_DGRAM = 2,
87 SOCKET_TYPE_RAW_IP = 3,
88 SOCKET_TYPE_RAW_ETH = 4
98 SOCKET_IP_PROTO_ICMP = 1,
99 SOCKET_IP_PROTO_IGMP = 2,
100 SOCKET_IP_PROTO_TCP = 6,
101 SOCKET_IP_PROTO_UDP = 17,
102 SOCKET_IP_PROTO_ICMPV6 = 58
112 SOCKET_ETH_PROTO_ALL = 0x0000,
113 SOCKET_ETH_PROTO_LLC = 0x05DC,
114 SOCKET_ETH_PROTO_IPV4 = 0x0800,
115 SOCKET_ETH_PROTO_ARP = 0x0806,
116 SOCKET_ETH_PROTO_IPV6 = 0x86DD
126 SOCKET_FLAG_PEEK = 0x0200,
127 SOCKET_FLAG_DONT_ROUTE = 0x0400,
128 SOCKET_FLAG_WAIT_ALL = 0x0800,
129 SOCKET_FLAG_DONT_WAIT = 0x0100,
130 SOCKET_FLAG_BREAK_CHAR = 0x1000,
131 SOCKET_FLAG_BREAK_CRLF = 0x100A,
132 SOCKET_FLAG_WAIT_ACK = 0x2000,
133 SOCKET_FLAG_NO_DELAY = 0x4000,
134 SOCKET_FLAG_DELAY = 0x8000
140#define SOCKET_FLAG_BREAK(c) (SOCKET_FLAG_BREAK_CHAR | LSB(c))
149 SOCKET_SD_RECEIVE = 0,
161 SOCKET_EVENT_NONE = 0x0000,
162 SOCKET_EVENT_ACCEPT = 0x0001,
163 SOCKET_EVENT_CONNECTED = 0x0002,
164 SOCKET_EVENT_CLOSED = 0x0004,
165 SOCKET_EVENT_TX_READY = 0x0008,
166 SOCKET_EVENT_TX_DONE = 0x0010,
167 SOCKET_EVENT_TX_ACKED = 0x0020,
168 SOCKET_EVENT_TX_SHUTDOWN = 0x0040,
169 SOCKET_EVENT_RX_READY = 0x0080,
170 SOCKET_EVENT_RX_SHUTDOWN = 0x0100,
171 SOCKET_EVENT_LINK_UP = 0x0200,
172 SOCKET_EVENT_LINK_DOWN = 0x0400
182 SOCKET_OPTION_REUSE_ADDR = 0x0001,
183 SOCKET_OPTION_BROADCAST = 0x0002,
184 SOCKET_OPTION_IPV4_MULTICAST_LOOP = 0x0004,
185 SOCKET_OPTION_IPV4_PKT_INFO = 0x0008,
186 SOCKET_OPTION_IPV4_RECV_TOS = 0x0010,
187 SOCKET_OPTION_IPV4_RECV_TTL = 0x0020,
188 SOCKET_OPTION_IPV6_MULTICAST_LOOP = 0x0040,
189 SOCKET_OPTION_IPV6_ONLY = 0x0080,
190 SOCKET_OPTION_IPV6_PKT_INFO = 0x0100,
191 SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS = 0x0200,
192 SOCKET_OPTION_IPV6_RECV_HOP_LIMIT = 0x0400,
193 SOCKET_OPTION_TCP_NO_DELAY = 0x0800
215 HOST_NAME_RESOLVER_ANY = 0,
216 HOST_NAME_RESOLVER_DNS = 1,
217 HOST_NAME_RESOLVER_MDNS = 2,
218 HOST_NAME_RESOLVER_NBNS = 4,
219 HOST_NAME_RESOLVER_LLMNR = 8
239#if (ETH_SUPPORT == ENABLED)
244#if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
247#if (ETH_TIMESTAMP_SUPPORT == ENABLED)
261 NetInterface *interface;
267 NetRxAncillary ancillary;
280 NetInterface *interface;
291#if (ETH_VLAN_SUPPORT == ENABLED)
295#if (ETH_VMAN_SUPPORT == ENABLED)
306#if (TCP_SUPPORT == ENABLED)
337#if (TCP_CONGEST_CONTROL_SUPPORT == ENABLED)
346#if (TCP_KEEP_ALIVE_SUPPORT == ENABLED)
355#if (TCP_SACK_SUPPORT == ENABLED)
384#if (UDP_SUPPORT == ENABLED || RAW_SOCKET_SUPPORT == ENABLED)
403extern const SocketMsg SOCKET_DEFAULT_MSG;
406extern Socket socketTable[SOCKET_MAX_COUNT];
411Socket *socketOpen(uint_t type, uint_t protocol);
415error_t socketSetTtl(Socket *socket, uint8_t ttl);
416error_t socketSetMulticastTtl(Socket *socket, uint8_t ttl);
418error_t socketSetDscp(Socket *socket, uint8_t dscp);
420error_t socketSetVlanPcp(Socket *socket, uint8_t pcp);
421error_t socketSetVlanDei(Socket *socket, bool_t dei);
422error_t socketSetVmanPcp(Socket *socket, uint8_t pcp);
423error_t socketSetVmanDei(Socket *socket, bool_t dei);
425error_t socketEnableBroadcast(Socket *socket, bool_t enabled);
426error_t socketJoinMulticastGroup(Socket *socket,
const IpAddr *groupAddr);
427error_t socketLeaveMulticastGroup(Socket *socket,
const IpAddr *groupAddr);
429error_t socketEnableKeepAlive(Socket *socket, bool_t enabled);
434error_t socketSetMaxSegmentSize(Socket *socket,
size_t mss);
436error_t socketSetTxBufferSize(Socket *socket,
size_t size);
437error_t socketSetRxBufferSize(Socket *socket,
size_t size);
439error_t socketSetInterface(Socket *socket, NetInterface *interface);
440NetInterface *socketGetInterface(Socket *socket);
445error_t socketConnect(Socket *socket,
const IpAddr *remoteIpAddr,
446 uint16_t remotePort);
448error_t socketListen(Socket *socket, uint_t backlog);
450Socket *socketAccept(Socket *socket,
IpAddr *clientIpAddr,
451 uint16_t *clientPort);
453error_t socketSend(Socket *socket,
const void *data,
size_t length,
454 size_t *written, uint_t flags);
456error_t socketSendTo(Socket *socket,
const IpAddr *destIpAddr, uint16_t destPort,
457 const void *data,
size_t length,
size_t *written, uint_t flags);
459error_t socketSendMsg(Socket *socket,
const SocketMsg *message, uint_t flags);
461error_t socketReceive(Socket *socket,
void *data,
462 size_t size,
size_t *received, uint_t flags);
464error_t socketReceiveFrom(Socket *socket,
IpAddr *srcIpAddr, uint16_t *srcPort,
465 void *data,
size_t size,
size_t *received, uint_t flags);
467error_t socketReceiveEx(Socket *socket,
IpAddr *srcIpAddr, uint16_t *srcPort,
468 IpAddr *destIpAddr,
void *data,
size_t size,
size_t *received, uint_t flags);
472error_t socketGetLocalAddr(Socket *socket,
IpAddr *localIpAddr,
473 uint16_t *localPort);
475error_t socketGetRemoteAddr(Socket *socket,
IpAddr *remoteIpAddr,
476 uint16_t *remotePort);
478error_t socketShutdown(Socket *socket, uint_t how);
479void socketClose(Socket *socket);
484error_t getHostByName(NetInterface *interface,
const char_t *name,
485 IpAddr *ipAddr, uint_t flags);
error_t
Error codes.
Definition error.h:43
IPv4 and IPv6 common routines.
uint_t OsEvent
Event object.
Definition os_port_none.h:104
uint32_t systime_t
System time.
Definition os_port_none.h:90
SocketEthProtocol
Ethernet protocols.
Definition socket.h:111
struct _SocketQueueItem SocketQueueItem
Receive queue item.
SocketFlags
Flags used by I/O functions.
Definition socket.h:125
SocketShutdownFlags
Flags used by shutdown function.
Definition socket.h:148
SocketIpProtocol
IP protocols.
Definition socket.h:97
SocketOptions
Socket options.
Definition socket.h:181
SocketType
Socket types.
Definition socket.h:83
HostType
Host types.
Definition socket.h:202
HostnameResolver
Name resolution protocols.
Definition socket.h:214
SocketEvent
Socket events.
Definition socket.h:160
IP network address.
Definition ip.h:72
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89
Timer.
Definition net_misc.h:171
Timestamp.
Definition net_misc.h:105
Structure describing socket events.
Definition socket.h:395
Socket * socket
Handle to a socket to monitor.
Definition socket.h:396
uint_t eventMask
Requested events.
Definition socket.h:397
uint_t eventFlags
Returned events.
Definition socket.h:398
Message and ancillary data.
Definition socket.h:228
size_t size
Size of the payload, in bytes.
Definition socket.h:230
uint16_t srcPort
Source port.
Definition socket.h:236
uint16_t destPort
Destination port.
Definition socket.h:238
uint8_t ttl
Time-to-live value.
Definition socket.h:232
int32_t timestampId
Unique identifier for hardware time stamping.
Definition socket.h:248
uint8_t tos
Type-of-service value.
Definition socket.h:233
IpAddr srcIpAddr
Source IP address.
Definition socket.h:235
NetInterface * interface
Underlying network interface.
Definition socket.h:234
uint8_t switchPort
Switch port identifier.
Definition socket.h:245
uint16_t ethType
Ethernet type field.
Definition socket.h:242
MacAddr destMacAddr
Destination MAC address.
Definition socket.h:241
IpAddr destIpAddr
Destination IP address.
Definition socket.h:237
NetTimestamp timestamp
Captured time stamp.
Definition socket.h:249
MacAddr srcMacAddr
Source MAC address.
Definition socket.h:240
size_t length
Actual length of the payload, in bytes.
Definition socket.h:231
void * data
Pointer to the payload.
Definition socket.h:229
Receive buffer.
Definition tcp.h:438
SACK block.
Definition tcp.h:415
Transmit buffer.
Definition tcp.h:426
Receive queue item.
Definition socket.h:259
Structure describing a socket.
Definition socket.h:276
bool_t closedFlag
The connection has been closed properly.
Definition socket.h:309
uint16_t maxSndWnd
Maximum send window it has seen so far on the connection.
Definition socket.h:322
systime_t rttStartTime
Round-trip start time.
Definition socket.h:332
uint16_t sndUser
Amount of data buffered but not yet sent.
Definition socket.h:320
uint_t retransmitCount
Number of retransmissions.
Definition socket.h:369
uint16_t sndWnd
Size of the send window.
Definition socket.h:321
uint16_t rcvWnd
Receive window.
Definition socket.h:328
systime_t keepAliveTimestamp
Keep-alive timestamp.
Definition socket.h:352
uint_t n
Number of bytes acknowledged during the whole round-trip.
Definition socket.h:342
uint32_t sndNxt
Sequence number of the next byte to be sent.
Definition socket.h:319
uint_t synQueueSize
Maximum number of pending connections for listening sockets.
Definition socket.h:372
NetTimer overrideTimer
Override timer.
Definition socket.h:378
uint8_t ttl
Time-to-live value for unicast datagrams.
Definition socket.h:288
bool_t rttBusy
RTT measurement is being performed.
Definition socket.h:330
uint32_t sndWl2
Segment acknowledgment number used for last window update.
Definition socket.h:324
uint32_t rcvNxt
Receive next sequence number.
Definition socket.h:326
int8_t vmanPcp
VMAN priority (802.1ad)
Definition socket.h:296
NetTimer persistTimer
Persist timer.
Definition socket.h:377
size_t txBufferSize
Size of the send buffer.
Definition socket.h:363
uint16_t cwnd
Congestion window.
Definition socket.h:339
int8_t vlanPcp
VLAN priority (802.1Q)
Definition socket.h:292
uint32_t sndWl1
Segment sequence number used for last window update.
Definition socket.h:323
uint32_t iss
Initial send sequence number.
Definition socket.h:315
systime_t keepAliveIdle
Keep-alive idle time.
Definition socket.h:348
TcpCongestState congestState
Congestion state.
Definition socket.h:338
int8_t vmanDei
Drop eligible indicator.
Definition socket.h:297
systime_t rttvar
Round-trip time variation.
Definition socket.h:334
uint_t wndProbeCount
Zero window probe counter.
Definition socket.h:374
uint8_t tos
Type-of-service value.
Definition socket.h:287
uint8_t multicastTtl
Time-to-live value for multicast datagrams.
Definition socket.h:289
uint16_t rcvUser
Number of data received but not yet consumed.
Definition socket.h:327
bool_t ownedFlag
The user is the owner of the TCP socket.
Definition socket.h:308
systime_t keepAliveInterval
Time interval between subsequent keep-alive probes.
Definition socket.h:349
uint_t sackBlockCount
Number of non-contiguous blocks that have been received.
Definition socket.h:360
uint_t dupAckCount
Number of consecutive duplicate ACKs.
Definition socket.h:341
TcpState state
Current state of the TCP finite state machine.
Definition socket.h:307
NetTimer finWait2Timer
FIN-WAIT-2 timer.
Definition socket.h:379
TcpSynQueueItem * synQueue
SYN queue for listening sockets.
Definition socket.h:371
bool_t sackPermitted
SACK Permitted option received.
Definition socket.h:356
bool_t keepAliveEnabled
Specifies whether TCP keep-alive mechanism is enabled.
Definition socket.h:347
uint32_t sndUna
Data that have been sent but not yet acknowledged.
Definition socket.h:318
bool_t resetFlag
The connection has been reset.
Definition socket.h:310
uint16_t mss
Maximum segment size.
Definition socket.h:312
int8_t vlanDei
Drop eligible indicator.
Definition socket.h:293
uint32_t recover
NewReno modification to TCP's fast recovery algorithm.
Definition socket.h:343
TcpQueueItem * retransmitQueue
Retransmission queue.
Definition socket.h:367
uint_t keepAliveMaxProbes
Number of keep-alive probes.
Definition socket.h:350
size_t rxBufferSize
Size of the receive buffer.
Definition socket.h:365
uint32_t options
Socket options.
Definition socket.h:285
uint32_t irs
Initial receive sequence number.
Definition socket.h:316
uint16_t rmss
Receiver maximum segment size.
Definition socket.h:314
uint_t keepAliveProbeCount
Keep-alive probe counter.
Definition socket.h:351
uint32_t rttSeqNum
Sequence number identifying a TCP segment.
Definition socket.h:331
systime_t rto
Retransmission timeout.
Definition socket.h:335
systime_t srtt
Smoothed round-trip time.
Definition socket.h:333
uint16_t ssthresh
Slow start threshold.
Definition socket.h:340
NetTimer retransmitTimer
Retransmission timer.
Definition socket.h:368
uint16_t smss
Sender maximum segment size.
Definition socket.h:313
IpAddr multicastGroups[SOCKET_MAX_MULTICAST_GROUPS]
Multicast groups.
Definition socket.h:290
TcpSackBlock sackBlock[TCP_MAX_SACK_BLOCKS]
List of non-contiguous blocks that have been received.
Definition socket.h:359
TcpTxBuffer txBuffer
Send buffer.
Definition socket.h:362
NetTimer timeWaitTimer
2MSL timer
Definition socket.h:380
TcpRxBuffer rxBuffer
Receive buffer.
Definition socket.h:364
systime_t wndProbeInterval
Interval between successive probes.
Definition socket.h:375
Retransmission queue item.
Definition tcp.h:382
SYN queue item.
Definition tcp.h:396
TCP (Transmission Control Protocol)
TcpState
TCP FSM states.
Definition tcp.h:267
TcpCongestState
TCP congestion states.
Definition tcp.h:287