Socket API. More...
#include "core/net.h"
#include "core/socket.h"
#include "core/socket_misc.h"
#include "core/raw_socket.h"
#include "core/udp.h"
#include "core/tcp.h"
#include "core/tcp_misc.h"
#include "dns/dns_client.h"
#include "mdns/mdns_client.h"
#include "netbios/nbns_client.h"
#include "llmnr/llmnr_client.h"
#include "debug.h"
Go to the source code of this file.
Macros | |
#define | TRACE_LEVEL SOCKET_TRACE_LEVEL |
Functions | |
error_t | socketInit (void) |
Socket related initialization. More... | |
Socket * | socketOpen (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... | |
NetInterface * | socketGetInterface (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... | |
Socket * | socketAccept (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 | |
Socket | socketTable [SOCKET_MAX_COUNT] |
const SocketMsg | SOCKET_DEFAULT_MSG |
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.
- Version
- 2.4.4
Definition in file socket.c.
Macro Definition Documentation
◆ TRACE_LEVEL
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] interface Underlying network interface (optional parameter) [in] name Name of the host to be resolved [out] ipAddr IP address corresponding to the specified host name [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ socketAccept()
Permit an incoming connection attempt on a socket.
- Parameters
-
[in] socket Handle to a socket previously placed in a listening state [out] clientIpAddr IP address of the client [out] clientPort Port number used by the client
- Returns
- Handle to the socket in which the actual connection is made
◆ socketAddMulticastSource()
◆ socketBind()
◆ socketBlockMulticastSource()
◆ socketClose()
void socketClose | ( | Socket * | socket | ) |
◆ socketConnect()
◆ socketDropMulticastSource()
◆ socketEnableBroadcast()
◆ socketEnableKeepAlive()
◆ socketGetInterface()
NetInterface* socketGetInterface | ( | Socket * | socket | ) |
◆ socketGetLocalAddr()
◆ socketGetMulticastSourceFilter()
error_t socketGetMulticastSourceFilter | ( | Socket * | socket, |
const IpAddr * | groupAddr, | ||
IpFilterMode * | filterMode, | ||
IpAddr * | sources, | ||
uint_t * | numSources | ||
) |
Get multicast source filter.
- Parameters
-
[in] socket Handle to a socket [in] groupAddr IP address identifying a multicast group [out] filterMode Multicast filter mode (include or exclude) [out] sources IP addresses of sources to include or exclude depending on the filter mode [out] numSources Number of source addresses in the list
- Returns
- Error code
◆ socketGetRemoteAddr()
◆ socketInit()
error_t socketInit | ( | void | ) |
◆ socketJoinMulticastGroup()
◆ socketLeaveMulticastGroup()
◆ socketListen()
Place a socket in the listening state.
Place a socket in a state in which it is listening for an incoming connection
- Parameters
-
[in] socket Socket to place in the listening state [in] backlog backlog The maximum length of the pending connection queue. If this parameter is zero, then the default backlog value is used instead
- Returns
- Error code
◆ socketOpen()
◆ 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] eventDesc Set of entries specifying the events the user is interested in [in] size Number of entries in the descriptor set [in] extEvent External event that can abort the wait if necessary (optional) [in] timeout Maximum time to wait before returning
- Returns
- Error code
◆ 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] socket Handle that identifies a connected socket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ 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] socket Handle that identifies a socket [out] srcIpAddr Source IP address (optional) [out] srcPort Source port number (optional) [out] destIpAddr Destination IP address (optional) [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ 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] socket Handle that identifies a socket [out] srcIpAddr Source IP address (optional) [out] srcPort Source port number (optional) [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ socketReceiveMsg()
◆ 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] socket Handle that identifies a connected socket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [out] written Actual number of bytes written (optional parameter) [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ socketSendMsg()
◆ 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] socket Handle that identifies a socket [in] destIpAddr IP address of the target host [in] destPort Target port number [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [out] written Actual number of bytes written (optional parameter) [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
◆ socketSetDscp()
◆ socketSetInterface()
error_t socketSetInterface | ( | Socket * | socket, |
NetInterface * | interface | ||
) |
◆ socketSetKeepAliveParams()
error_t socketSetKeepAliveParams | ( | Socket * | socket, |
systime_t | idle, | ||
systime_t | interval, | ||
uint_t | maxProbes | ||
) |
Set TCP keep-alive parameters.
- Parameters
-
[in] socket Handle to a socket [in] idle Time interval between last data packet sent and first keep-alive probe [in] interval Time interval between subsequent keep-alive probes [in] maxProbes Number of unacknowledged keep-alive probes to send before considering the connection is dead
- Returns
- Error code
◆ socketSetMaxSegmentSize()
◆ 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] socket Handle to a socket [in] groupAddr IP address identifying a multicast group [in] filterMode Multicast filter mode (include or exclude) [in] sources IP addresses of sources to include or exclude depending on the filter mode [in] numSources Number of source addresses in the list
- Returns
- Error code
◆ socketSetMulticastTtl()
◆ socketSetRxBufferSize()
◆ socketSetTimeout()
◆ socketSetTtl()
◆ socketSetTxBufferSize()
◆ socketSetVlanDei()
◆ socketSetVlanPcp()
◆ socketSetVmanDei()
◆ socketSetVmanPcp()
◆ socketShutdown()
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] socket Handle to a socket [in] how Flag that describes what types of operation will no longer be allowed
- Returns
- Error code
◆ socketUnblockMulticastSource()
Variable Documentation
◆ SOCKET_DEFAULT_MSG
const SocketMsg SOCKET_DEFAULT_MSG |
◆ socketTable
Socket socketTable[SOCKET_MAX_COUNT] |