socket.h File Reference

Socket API. More...

#include "core/net.h"
#include "core/ethernet.h"
#include "core/ip.h"
#include "core/tcp.h"

Go to the source code of this file.

Data Structures

struct  SocketMsg
 Message and ancillary data. More...
 
struct  SocketMulticastGroup
 Multicast group. More...
 
struct  _SocketQueueItem
 Receive queue item. More...
 
struct  _Socket
 Structure describing a socket. More...
 
struct  SocketEventDesc
 Structure describing socket events. More...
 

Macros

#define Socket   struct _Socket
 
#define SOCKET_MAX_COUNT   16
 
#define SOCKET_MAX_MULTICAST_GROUPS   1
 
#define SOCKET_MAX_MULTICAST_SOURCES   0
 
#define SOCKET_EPHEMERAL_PORT_MIN   49152
 
#define SOCKET_EPHEMERAL_PORT_MAX   65535
 
#define SOCKET_FLAG_BREAK(c)   (SOCKET_FLAG_BREAK_CHAR | LSB(c))
 

Typedefs

typedef struct _SocketQueueItem SocketQueueItem
 Receive queue item. More...
 

Enumerations

enum  SocketType {
  SOCKET_TYPE_UNUSED = 0, SOCKET_TYPE_STREAM = 1, SOCKET_TYPE_DGRAM = 2, SOCKET_TYPE_RAW_IP = 3,
  SOCKET_TYPE_RAW_ETH = 4
}
 Socket types. More...
 
enum  SocketIpProtocol {
  SOCKET_IP_PROTO_ICMP = 1, SOCKET_IP_PROTO_IGMP = 2, SOCKET_IP_PROTO_TCP = 6, SOCKET_IP_PROTO_UDP = 17,
  SOCKET_IP_PROTO_ICMPV6 = 58
}
 IP protocols. More...
 
enum  SocketEthProtocol {
  SOCKET_ETH_PROTO_ALL = 0x0000, SOCKET_ETH_PROTO_LLC = 0x05DC, SOCKET_ETH_PROTO_IPV4 = 0x0800, SOCKET_ETH_PROTO_ARP = 0x0806,
  SOCKET_ETH_PROTO_IPV6 = 0x86DD, SOCKET_ETH_PROTO_EAPOL = 0x888E, SOCKET_ETH_PROTO_LLDP = 0x88CC, SOCKET_ETH_PROTO_PTP = 0x88F7
}
 Ethernet protocols. More...
 
enum  SocketFlags {
  SOCKET_FLAG_PEEK = 0x0200, SOCKET_FLAG_DONT_ROUTE = 0x0400, SOCKET_FLAG_WAIT_ALL = 0x0800, SOCKET_FLAG_DONT_WAIT = 0x0100,
  SOCKET_FLAG_BREAK_CHAR = 0x1000, SOCKET_FLAG_BREAK_CRLF = 0x100A, SOCKET_FLAG_WAIT_ACK = 0x2000, SOCKET_FLAG_NO_DELAY = 0x4000,
  SOCKET_FLAG_DELAY = 0x8000
}
 Flags used by I/O functions. More...
 
enum  SocketShutdownFlags { SOCKET_SD_RECEIVE = 0, SOCKET_SD_SEND = 1, SOCKET_SD_BOTH = 2 }
 Flags used by shutdown function. More...
 
enum  SocketEvent {
  SOCKET_EVENT_NONE = 0x0000, SOCKET_EVENT_ACCEPT = 0x0001, SOCKET_EVENT_CONNECTED = 0x0002, SOCKET_EVENT_CLOSED = 0x0004,
  SOCKET_EVENT_TX_READY = 0x0008, SOCKET_EVENT_TX_DONE = 0x0010, SOCKET_EVENT_TX_ACKED = 0x0020, SOCKET_EVENT_TX_SHUTDOWN = 0x0040,
  SOCKET_EVENT_RX_READY = 0x0080, SOCKET_EVENT_RX_SHUTDOWN = 0x0100, SOCKET_EVENT_LINK_UP = 0x0200, SOCKET_EVENT_LINK_DOWN = 0x0400
}
 Socket events. More...
 
enum  SocketOptions {
  SOCKET_OPTION_REUSE_ADDR = 0x0001, SOCKET_OPTION_BROADCAST = 0x0002, SOCKET_OPTION_IPV4_MULTICAST_LOOP = 0x0004, SOCKET_OPTION_IPV4_DONT_FRAG = 0x0008,
  SOCKET_OPTION_IPV4_PKT_INFO = 0x0010, SOCKET_OPTION_IPV4_RECV_TOS = 0x0020, SOCKET_OPTION_IPV4_RECV_TTL = 0x0040, SOCKET_OPTION_IPV6_MULTICAST_LOOP = 0x0080,
  SOCKET_OPTION_IPV6_ONLY = 0x0100, SOCKET_OPTION_IPV6_DONT_FRAG = 0x0200, SOCKET_OPTION_IPV6_PKT_INFO = 0x0400, SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS = 0x0800,
  SOCKET_OPTION_IPV6_RECV_HOP_LIMIT = 0x1000, SOCKET_OPTION_TCP_NO_DELAY = 0x2000, SOCKET_OPTION_UDP_NO_CHECKSUM = 0x4000
}
 Socket options. More...
 
enum  HostType { HOST_TYPE_ANY = 0, HOST_TYPE_IPV4 = 16, HOST_TYPE_IPV6 = 32 }
 Host types. More...
 
enum  HostnameResolver {
  HOST_NAME_RESOLVER_ANY = 0, HOST_NAME_RESOLVER_DNS = 1, HOST_NAME_RESOLVER_MDNS = 2, HOST_NAME_RESOLVER_NBNS = 4,
  HOST_NAME_RESOLVER_LLMNR = 8
}
 Name resolution protocols. More...
 

Functions

error_t socketInit (void)
 Socket related initialization. More...
 
SocketsocketOpen (uint_t type, uint_t protocol)
 Create a socket (UDP or TCP) More...
 
error_t socketSetTimeout (Socket *socket, systime_t timeout)
 Set timeout value for blocking operations. More...
 
error_t socketSetTtl (Socket *socket, uint8_t ttl)
 Set TTL value for unicast datagrams. More...
 
error_t socketSetMulticastTtl (Socket *socket, uint8_t ttl)
 Set TTL value for multicast datagrams. More...
 
error_t socketSetDscp (Socket *socket, uint8_t dscp)
 Set DSCP field. More...
 
error_t socketSetVlanPcp (Socket *socket, uint8_t pcp)
 Set VLAN priority. More...
 
error_t socketSetVlanDei (Socket *socket, bool_t dei)
 Set VLAN DEI flag. More...
 
error_t socketSetVmanPcp (Socket *socket, uint8_t pcp)
 Set VMAN priority. More...
 
error_t socketSetVmanDei (Socket *socket, bool_t dei)
 Set VMAN DEI flag. More...
 
error_t socketEnableBroadcast (Socket *socket, bool_t enabled)
 Enable reception of broadcast messages. More...
 
error_t socketJoinMulticastGroup (Socket *socket, const IpAddr *groupAddr)
 Join the specified host group. More...
 
error_t socketLeaveMulticastGroup (Socket *socket, const IpAddr *groupAddr)
 Leave the specified host group. More...
 
error_t socketSetMulticastSourceFilter (Socket *socket, const IpAddr *groupAddr, IpFilterMode filterMode, const IpAddr *sources, uint_t numSources)
 Set multicast source filter (full-state API) More...
 
error_t socketGetMulticastSourceFilter (Socket *socket, const IpAddr *groupAddr, IpFilterMode *filterMode, IpAddr *sources, uint_t *numSources)
 Get multicast source filter. More...
 
error_t socketAddMulticastSource (Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
 Accept specific source for specific group (delta-based API) More...
 
error_t socketDropMulticastSource (Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
 Drop specific source for specific group (delta-based API) More...
 
error_t socketBlockMulticastSource (Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
 Block specific source for specific group (delta-based API) More...
 
error_t socketUnblockMulticastSource (Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
 Unblock specific source for specific group (delta-based API) More...
 
error_t socketEnableKeepAlive (Socket *socket, bool_t enabled)
 Enable TCP keep-alive. More...
 
error_t socketSetKeepAliveParams (Socket *socket, systime_t idle, systime_t interval, uint_t maxProbes)
 Set TCP keep-alive parameters. More...
 
error_t socketSetMaxSegmentSize (Socket *socket, size_t mss)
 Specify the maximum segment size for outgoing TCP packets. More...
 
error_t socketSetTxBufferSize (Socket *socket, size_t size)
 Specify the size of the TCP send buffer. More...
 
error_t socketSetRxBufferSize (Socket *socket, size_t size)
 Specify the size of the TCP receive buffer. More...
 
error_t socketSetInterface (Socket *socket, NetInterface *interface)
 Bind a socket to a particular network interface. More...
 
NetInterfacesocketGetInterface (Socket *socket)
 Retrieve the underlying interface. More...
 
error_t socketBind (Socket *socket, const IpAddr *localIpAddr, uint16_t localPort)
 Associate a local address with a socket. More...
 
error_t socketConnect (Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort)
 Establish a connection to a specified socket. More...
 
error_t socketListen (Socket *socket, uint_t backlog)
 Place a socket in the listening state. More...
 
SocketsocketAccept (Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort)
 Permit an incoming connection attempt on a socket. More...
 
error_t socketSend (Socket *socket, const void *data, size_t length, size_t *written, uint_t flags)
 Send data to a connected socket. More...
 
error_t socketSendTo (Socket *socket, const IpAddr *destIpAddr, uint16_t destPort, const void *data, size_t length, size_t *written, uint_t flags)
 Send a datagram to a specific destination. More...
 
error_t socketSendMsg (Socket *socket, const SocketMsg *message, uint_t flags)
 Send a message to a connectionless socket. More...
 
error_t socketReceive (Socket *socket, void *data, size_t size, size_t *received, uint_t flags)
 Receive data from a connected socket. More...
 
error_t socketReceiveFrom (Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, void *data, size_t size, size_t *received, uint_t flags)
 Receive a datagram from a connectionless socket. More...
 
error_t socketReceiveEx (Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags)
 Receive a datagram. More...
 
error_t socketReceiveMsg (Socket *socket, SocketMsg *message, uint_t flags)
 Receive a message from a connectionless socket. More...
 
error_t socketGetLocalAddr (Socket *socket, IpAddr *localIpAddr, uint16_t *localPort)
 Retrieve the local address for a given socket. More...
 
error_t socketGetRemoteAddr (Socket *socket, IpAddr *remoteIpAddr, uint16_t *remotePort)
 Retrieve the address of the peer to which a socket is connected. More...
 
error_t socketShutdown (Socket *socket, uint_t how)
 Disable reception, transmission, or both. More...
 
void socketClose (Socket *socket)
 Close an existing socket. More...
 
error_t socketPoll (SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
 Wait for one of a set of sockets to become ready to perform I/O. More...
 
error_t getHostByName (NetInterface *interface, const char_t *name, IpAddr *ipAddr, uint_t flags)
 Resolve a host name into an IP address. More...
 

Variables

const SocketMsg SOCKET_DEFAULT_MSG
 
Socket socketTable [SOCKET_MAX_COUNT]
 

Detailed Description

Socket API.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file socket.h.

Macro Definition Documentation

◆ Socket

#define Socket   struct _Socket

Definition at line 36 of file socket.h.

◆ SOCKET_EPHEMERAL_PORT_MAX

#define SOCKET_EPHEMERAL_PORT_MAX   65535

Definition at line 74 of file socket.h.

◆ SOCKET_EPHEMERAL_PORT_MIN

#define SOCKET_EPHEMERAL_PORT_MIN   49152

Definition at line 67 of file socket.h.

◆ SOCKET_FLAG_BREAK

#define SOCKET_FLAG_BREAK (   c)    (SOCKET_FLAG_BREAK_CHAR | LSB(c))

Definition at line 150 of file socket.h.

◆ SOCKET_MAX_COUNT

#define SOCKET_MAX_COUNT   16

Definition at line 46 of file socket.h.

◆ SOCKET_MAX_MULTICAST_GROUPS

#define SOCKET_MAX_MULTICAST_GROUPS   1

Definition at line 53 of file socket.h.

◆ SOCKET_MAX_MULTICAST_SOURCES

#define SOCKET_MAX_MULTICAST_SOURCES   0

Definition at line 60 of file socket.h.

Typedef Documentation

◆ SocketQueueItem

Receive queue item.

Enumeration Type Documentation

◆ HostnameResolver

Name resolution protocols.

Enumerator
HOST_NAME_RESOLVER_ANY 
HOST_NAME_RESOLVER_DNS 
HOST_NAME_RESOLVER_MDNS 
HOST_NAME_RESOLVER_NBNS 
HOST_NAME_RESOLVER_LLMNR 

Definition at line 226 of file socket.h.

◆ HostType

enum HostType

Host types.

Enumerator
HOST_TYPE_ANY 
HOST_TYPE_IPV4 
HOST_TYPE_IPV6 

Definition at line 214 of file socket.h.

◆ SocketEthProtocol

Ethernet protocols.

Enumerator
SOCKET_ETH_PROTO_ALL 
SOCKET_ETH_PROTO_LLC 
SOCKET_ETH_PROTO_IPV4 
SOCKET_ETH_PROTO_ARP 
SOCKET_ETH_PROTO_IPV6 
SOCKET_ETH_PROTO_EAPOL 
SOCKET_ETH_PROTO_LLDP 
SOCKET_ETH_PROTO_PTP 

Definition at line 117 of file socket.h.

◆ SocketEvent

Socket events.

Enumerator
SOCKET_EVENT_NONE 
SOCKET_EVENT_ACCEPT 
SOCKET_EVENT_CONNECTED 
SOCKET_EVENT_CLOSED 
SOCKET_EVENT_TX_READY 
SOCKET_EVENT_TX_DONE 
SOCKET_EVENT_TX_ACKED 
SOCKET_EVENT_TX_SHUTDOWN 
SOCKET_EVENT_RX_READY 
SOCKET_EVENT_RX_SHUTDOWN 
SOCKET_EVENT_LINK_UP 
SOCKET_EVENT_LINK_DOWN 

Definition at line 169 of file socket.h.

◆ SocketFlags

Flags used by I/O functions.

Enumerator
SOCKET_FLAG_PEEK 
SOCKET_FLAG_DONT_ROUTE 
SOCKET_FLAG_WAIT_ALL 
SOCKET_FLAG_DONT_WAIT 
SOCKET_FLAG_BREAK_CHAR 
SOCKET_FLAG_BREAK_CRLF 
SOCKET_FLAG_WAIT_ACK 
SOCKET_FLAG_NO_DELAY 
SOCKET_FLAG_DELAY 

Definition at line 134 of file socket.h.

◆ SocketIpProtocol

IP protocols.

Enumerator
SOCKET_IP_PROTO_ICMP 
SOCKET_IP_PROTO_IGMP 
SOCKET_IP_PROTO_TCP 
SOCKET_IP_PROTO_UDP 
SOCKET_IP_PROTO_ICMPV6 

Definition at line 103 of file socket.h.

◆ SocketOptions

Socket options.

Enumerator
SOCKET_OPTION_REUSE_ADDR 
SOCKET_OPTION_BROADCAST 
SOCKET_OPTION_IPV4_MULTICAST_LOOP 
SOCKET_OPTION_IPV4_DONT_FRAG 
SOCKET_OPTION_IPV4_PKT_INFO 
SOCKET_OPTION_IPV4_RECV_TOS 
SOCKET_OPTION_IPV4_RECV_TTL 
SOCKET_OPTION_IPV6_MULTICAST_LOOP 
SOCKET_OPTION_IPV6_ONLY 
SOCKET_OPTION_IPV6_DONT_FRAG 
SOCKET_OPTION_IPV6_PKT_INFO 
SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS 
SOCKET_OPTION_IPV6_RECV_HOP_LIMIT 
SOCKET_OPTION_TCP_NO_DELAY 
SOCKET_OPTION_UDP_NO_CHECKSUM 

Definition at line 190 of file socket.h.

◆ SocketShutdownFlags

Flags used by shutdown function.

Enumerator
SOCKET_SD_RECEIVE 
SOCKET_SD_SEND 
SOCKET_SD_BOTH 

Definition at line 157 of file socket.h.

◆ SocketType

enum SocketType

Socket types.

Enumerator
SOCKET_TYPE_UNUSED 
SOCKET_TYPE_STREAM 
SOCKET_TYPE_DGRAM 
SOCKET_TYPE_RAW_IP 
SOCKET_TYPE_RAW_ETH 

Definition at line 89 of file socket.h.

Function Documentation

◆ getHostByName()

error_t getHostByName ( NetInterface interface,
const char_t name,
IpAddr ipAddr,
uint_t  flags 
)

Resolve a host name into an IP address.

Parameters
[in]interfaceUnderlying network interface (optional parameter)
[in]nameName of the host to be resolved
[out]ipAddrIP address corresponding to the specified host name
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 2274 of file socket.c.

◆ socketAccept()

Socket* socketAccept ( Socket socket,
IpAddr clientIpAddr,
uint16_t *  clientPort 
)

Permit an incoming connection attempt on a socket.

Parameters
[in]socketHandle to a socket previously placed in a listening state
[out]clientIpAddrIP address of the client
[out]clientPortPort number used by the client
Returns
Handle to the socket in which the actual connection is made

Definition at line 1451 of file socket.c.

◆ socketAddMulticastSource()

error_t socketAddMulticastSource ( Socket socket,
const IpAddr groupAddr,
const IpAddr srcAddr 
)

Accept specific source for specific group (delta-based API)

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[in]srcAddrSource IP address to accept
Returns
Error code

Definition at line 753 of file socket.c.

◆ socketBind()

error_t socketBind ( Socket socket,
const IpAddr localIpAddr,
uint16_t  localPort 
)

Associate a local address with a socket.

Parameters
[in]socketHandle to a socket
[in]localIpAddrLocal address to assign to the bound socket
[in]localPortLocal port number to assign to the bound socket
Returns
Error code

Definition at line 1316 of file socket.c.

◆ socketBlockMulticastSource()

error_t socketBlockMulticastSource ( Socket socket,
const IpAddr groupAddr,
const IpAddr srcAddr 
)

Block specific source for specific group (delta-based API)

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[in]srcAddrSource IP address to block
Returns
Error code

Definition at line 917 of file socket.c.

◆ socketClose()

void socketClose ( Socket socket)

Close an existing socket.

Parameters
[in]socketHandle identifying the socket to close

Definition at line 2062 of file socket.c.

◆ socketConnect()

error_t socketConnect ( Socket socket,
const IpAddr remoteIpAddr,
uint16_t  remotePort 
)

Establish a connection to a specified socket.

Parameters
[in]socketHandle to an unconnected socket
[in]remoteIpAddrIP address of the remote host
[in]remotePortRemote port number that will be used to establish the connection
Returns
Error code

Definition at line 1349 of file socket.c.

◆ socketDropMulticastSource()

error_t socketDropMulticastSource ( Socket socket,
const IpAddr groupAddr,
const IpAddr srcAddr 
)

Drop specific source for specific group (delta-based API)

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[in]srcAddrSource IP address to drop
Returns
Error code

Definition at line 840 of file socket.c.

◆ socketEnableBroadcast()

error_t socketEnableBroadcast ( Socket socket,
bool_t  enabled 
)

Enable reception of broadcast messages.

Parameters
[in]socketHandle to a socket
[in]enabledSpecifies whether broadcast messages should be accepted
Returns
Error code

Definition at line 392 of file socket.c.

◆ socketEnableKeepAlive()

error_t socketEnableKeepAlive ( Socket socket,
bool_t  enabled 
)

Enable TCP keep-alive.

Parameters
[in]socketHandle to a socket
[in]enabledSpecifies whether TCP keep-alive is enabled
Returns
Error code

Definition at line 1073 of file socket.c.

◆ socketGetInterface()

NetInterface* socketGetInterface ( Socket socket)

Retrieve the underlying interface.

Parameters
[in]socketHandle to a socket
Returns
Pointer to the underlying network interface

Definition at line 1293 of file socket.c.

◆ socketGetLocalAddr()

error_t socketGetLocalAddr ( Socket socket,
IpAddr localIpAddr,
uint16_t *  localPort 
)

Retrieve the local address for a given socket.

Parameters
[in]socketHandle that identifies a socket
[out]localIpAddrLocal IP address (optional)
[out]localPortLocal port number (optional)
Returns
Error code

Definition at line 1953 of file socket.c.

◆ socketGetMulticastSourceFilter()

error_t socketGetMulticastSourceFilter ( Socket socket,
const IpAddr groupAddr,
IpFilterMode filterMode,
IpAddr sources,
uint_t numSources 
)

Get multicast source filter.

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[out]filterModeMulticast filter mode (include or exclude)
[out]sourcesIP addresses of sources to include or exclude depending on the filter mode
[out]numSourcesNumber of source addresses in the list
Returns
Error code

Definition at line 679 of file socket.c.

◆ socketGetRemoteAddr()

error_t socketGetRemoteAddr ( Socket socket,
IpAddr remoteIpAddr,
uint16_t *  remotePort 
)

Retrieve the address of the peer to which a socket is connected.

Parameters
[in]socketHandle that identifies a socket
[out]remoteIpAddrIP address of the remote host (optional)
[out]remotePortRemote port number (optional)
Returns
Error code

Definition at line 1985 of file socket.c.

◆ socketInit()

error_t socketInit ( void  )

Socket related initialization.

Returns
Error code

Definition at line 85 of file socket.c.

◆ socketJoinMulticastGroup()

error_t socketJoinMulticastGroup ( Socket socket,
const IpAddr groupAddr 
)

Join the specified host group.

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying the host group to join
Returns
Error code

Definition at line 426 of file socket.c.

◆ socketLeaveMulticastGroup()

error_t socketLeaveMulticastGroup ( Socket socket,
const IpAddr groupAddr 
)

Leave the specified host group.

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying the host group to leave
Returns
Error code

Definition at line 494 of file socket.c.

◆ socketListen()

error_t socketListen ( Socket socket,
uint_t  backlog 
)

Place a socket in the listening state.

Place a socket in a state in which it is listening for an incoming connection

Parameters
[in]socketSocket to place in the listening state
[in]backlogbacklog The maximum length of the pending connection queue. If this parameter is zero, then the default backlog value is used instead
Returns
Error code

Definition at line 1413 of file socket.c.

◆ socketOpen()

Socket* socketOpen ( uint_t  type,
uint_t  protocol 
)

Create a socket (UDP or TCP)

Parameters
[in]typeType specification for the new socket
[in]protocolProtocol to be used
Returns
Handle referencing the new socket

Definition at line 125 of file socket.c.

◆ socketPoll()

error_t socketPoll ( SocketEventDesc eventDesc,
uint_t  size,
OsEvent extEvent,
systime_t  timeout 
)

Wait for one of a set of sockets to become ready to perform I/O.

This function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O

Parameters
[in,out]eventDescSet of entries specifying the events the user is interested in
[in]sizeNumber of entries in the descriptor set
[in]extEventExternal event that can abort the wait if necessary (optional)
[in]timeoutMaximum time to wait before returning
Returns
Error code

Definition at line 2149 of file socket.c.

◆ socketReceive()

error_t socketReceive ( Socket socket,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive data from a connected socket.

Parameters
[in]socketHandle that identifies a connected socket
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1692 of file socket.c.

◆ socketReceiveEx()

error_t socketReceiveEx ( Socket socket,
IpAddr srcIpAddr,
uint16_t *  srcPort,
IpAddr destIpAddr,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive a datagram.

Parameters
[in]socketHandle that identifies a socket
[out]srcIpAddrSource IP address (optional)
[out]srcPortSource port number (optional)
[out]destIpAddrDestination IP address (optional)
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1736 of file socket.c.

◆ socketReceiveFrom()

error_t socketReceiveFrom ( Socket socket,
IpAddr srcIpAddr,
uint16_t *  srcPort,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive a datagram from a connectionless socket.

Parameters
[in]socketHandle that identifies a socket
[out]srcIpAddrSource IP address (optional)
[out]srcPortSource port number (optional)
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1714 of file socket.c.

◆ socketReceiveMsg()

error_t socketReceiveMsg ( Socket socket,
SocketMsg message,
uint_t  flags 
)

Receive a message from a connectionless socket.

Parameters
[in]socketHandle that identifies a socket
[in,out]messagePointer to the structure describing the message
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1894 of file socket.c.

◆ socketSend()

error_t socketSend ( Socket socket,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send data to a connected socket.

Parameters
[in]socketHandle that identifies a connected socket
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of data bytes to send
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1486 of file socket.c.

◆ socketSendMsg()

error_t socketSendMsg ( Socket socket,
const SocketMsg message,
uint_t  flags 
)

Send a message to a connectionless socket.

Parameters
[in]socketHandle that identifies a socket
[in]messagePointer to the structure describing the message
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1634 of file socket.c.

◆ socketSendTo()

error_t socketSendTo ( Socket socket,
const IpAddr destIpAddr,
uint16_t  destPort,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send a datagram to a specific destination.

Parameters
[in]socketHandle that identifies a socket
[in]destIpAddrIP address of the target host
[in]destPortTarget port number
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of data bytes to send
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1507 of file socket.c.

◆ socketSetDscp()

error_t socketSetDscp ( Socket socket,
uint8_t  dscp 
)

Set DSCP field.

Parameters
[in]socketHandle to a socket
[in]dscpDifferentiated services codepoint
Returns
Error code

Definition at line 223 of file socket.c.

◆ socketSetInterface()

error_t socketSetInterface ( Socket socket,
NetInterface interface 
)

Bind a socket to a particular network interface.

Parameters
[in]socketHandle to a socket
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 1273 of file socket.c.

◆ socketSetKeepAliveParams()

error_t socketSetKeepAliveParams ( Socket socket,
systime_t  idle,
systime_t  interval,
uint_t  maxProbes 
)

Set TCP keep-alive parameters.

Parameters
[in]socketHandle to a socket
[in]idleTime interval between last data packet sent and first keep-alive probe
[in]intervalTime interval between subsequent keep-alive probes
[in]maxProbesNumber of unacknowledged keep-alive probes to send before considering the connection is dead
Returns
Error code

Definition at line 1122 of file socket.c.

◆ socketSetMaxSegmentSize()

error_t socketSetMaxSegmentSize ( Socket socket,
size_t  mss 
)

Specify the maximum segment size for outgoing TCP packets.

Parameters
[in]socketHandle to a socket
[in]mssMaximum segment size, in bytes
Returns
Error code

Definition at line 1164 of file socket.c.

◆ socketSetMulticastSourceFilter()

error_t socketSetMulticastSourceFilter ( Socket socket,
const IpAddr groupAddr,
IpFilterMode  filterMode,
const IpAddr sources,
uint_t  numSources 
)

Set multicast source filter (full-state API)

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[in]filterModeMulticast filter mode (include or exclude)
[in]sourcesIP addresses of sources to include or exclude depending on the filter mode
[in]numSourcesNumber of source addresses in the list
Returns
Error code

Definition at line 562 of file socket.c.

◆ socketSetMulticastTtl()

error_t socketSetMulticastTtl ( Socket socket,
uint8_t  ttl 
)

Set TTL value for multicast datagrams.

Parameters
[in]socketHandle to a socket
[in]ttlTime-to-live value
Returns
Error code

Definition at line 198 of file socket.c.

◆ socketSetRxBufferSize()

error_t socketSetRxBufferSize ( Socket socket,
size_t  size 
)

Specify the size of the TCP receive buffer.

Parameters
[in]socketHandle to a socket
[in]sizeDesired buffer size, in bytes
Returns
Error code

Definition at line 1237 of file socket.c.

◆ socketSetTimeout()

error_t socketSetTimeout ( Socket socket,
systime_t  timeout 
)

Set timeout value for blocking operations.

Parameters
[in]socketHandle to a socket
[in]timeoutMaximum time to wait
Returns
Error code

Definition at line 148 of file socket.c.

◆ socketSetTtl()

error_t socketSetTtl ( Socket socket,
uint8_t  ttl 
)

Set TTL value for unicast datagrams.

Parameters
[in]socketHandle to a socket
[in]ttlTime-to-live value
Returns
Error code

Definition at line 173 of file socket.c.

◆ socketSetTxBufferSize()

error_t socketSetTxBufferSize ( Socket socket,
size_t  size 
)

Specify the size of the TCP send buffer.

Parameters
[in]socketHandle to a socket
[in]sizeDesired buffer size, in bytes
Returns
Error code

Definition at line 1201 of file socket.c.

◆ socketSetVlanDei()

error_t socketSetVlanDei ( Socket socket,
bool_t  dei 
)

Set VLAN DEI flag.

Parameters
[in]socketHandle to a socket
[in]deiDrop eligible indicator
Returns
Error code

Definition at line 289 of file socket.c.

◆ socketSetVlanPcp()

error_t socketSetVlanPcp ( Socket socket,
uint8_t  pcp 
)

Set VLAN priority.

Parameters
[in]socketHandle to a socket
[in]pcpVLAN priority value
Returns
Error code

Definition at line 252 of file socket.c.

◆ socketSetVmanDei()

error_t socketSetVmanDei ( Socket socket,
bool_t  dei 
)

Set VMAN DEI flag.

Parameters
[in]socketHandle to a socket
[in]deiDrop eligible indicator
Returns
Error code

Definition at line 359 of file socket.c.

◆ socketSetVmanPcp()

error_t socketSetVmanPcp ( Socket socket,
uint8_t  pcp 
)

Set VMAN priority.

Parameters
[in]socketHandle to a socket
[in]pcpVLAN priority value
Returns
Error code

Definition at line 322 of file socket.c.

◆ socketShutdown()

error_t socketShutdown ( Socket socket,
uint_t  how 
)

Disable reception, transmission, or both.

Note that socketShutdown() does not close the socket, and resources attached to the socket will not be freed until socketClose() is invoked

Parameters
[in]socketHandle to a socket
[in]howFlag that describes what types of operation will no longer be allowed
Returns
Error code

Definition at line 2020 of file socket.c.

◆ socketUnblockMulticastSource()

error_t socketUnblockMulticastSource ( Socket socket,
const IpAddr groupAddr,
const IpAddr srcAddr 
)

Unblock specific source for specific group (delta-based API)

Parameters
[in]socketHandle to a socket
[in]groupAddrIP address identifying a multicast group
[in]srcAddrSource IP address to unblock
Returns
Error code

Definition at line 1004 of file socket.c.

Variable Documentation

◆ SOCKET_DEFAULT_MSG

const SocketMsg SOCKET_DEFAULT_MSG
extern

Definition at line 52 of file socket.c.

◆ socketTable

Socket socketTable[SOCKET_MAX_COUNT]
extern

Definition at line 49 of file socket.c.