Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
bsd_socket.c File Reference
BSD socket API. More...
Go to the source code of this file.
Functions | |
| int_t | socketTranslateErrorCode (error_t error) |
| Translate error code. | |
| int_t | socket (int_t family, int_t type, int_t protocol) |
| Create a socket that is bound to a specific transport service provider. | |
| int_t | bind (int_t s, const sockaddr *addr, socklen_t addrlen) |
| Associate a local address with a socket. | |
| int_t | connect (int_t s, const sockaddr *addr, socklen_t addrlen) |
| Establish a connection to a specified socket. | |
| int_t | listen (int_t s, int_t backlog) |
| Place a socket in the listening state. | |
| int_t | accept (int_t s, sockaddr *addr, socklen_t *addrlen) |
| Permit an incoming connection attempt on a socket. | |
| int_t | send (int_t s, const void *data, size_t length, int_t flags) |
| Send data to a connected socket. | |
| int_t | sendto (int_t s, const void *data, size_t length, int_t flags, const sockaddr *addr, socklen_t addrlen) |
| Send a datagram to a specific destination. | |
| int_t | recv (int_t s, void *data, size_t size, int_t flags) |
| Receive data from a connected socket. | |
| int_t | recvfrom (int_t s, void *data, size_t size, int_t flags, sockaddr *addr, socklen_t *addrlen) |
| Receive a datagram. | |
| int_t | getsockname (int_t s, sockaddr *addr, socklen_t *addrlen) |
| Retrieves the local name for a socket. | |
| int_t | getpeername (int_t s, sockaddr *addr, socklen_t *addrlen) |
| Retrieves the address of the peer to which a socket is connected. | |
| int_t | setsockopt (int_t s, int_t level, int_t optname, const void *optval, socklen_t optlen) |
| The setsockopt function sets a socket option. | |
| int_t | getsockopt (int_t s, int_t level, int_t optname, void *optval, socklen_t *optlen) |
| The getsockopt function retrieves a socket option. | |
| int_t | ioctlsocket (int_t s, uint32_t cmd, void *arg) |
| Control the I/O mode of a socket. | |
| int_t | fcntl (int_t s, int_t cmd, void *arg) |
| Perform specific operation. | |
| int_t | shutdown (int_t s, int_t how) |
| The shutdown function disables sends or receives on a socket. | |
| int_t | closesocket (int_t s) |
| The closesocket function closes an existing socket. | |
| int_t | select (int_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const timeval *timeout) |
| Determine the status of one or more sockets. | |
| void | selectFdZero (fd_set *fds) |
| Initializes a descriptor set. | |
| void | selectFdSet (fd_set *fds, int_t s) |
| Add a descriptor to an existing set. | |
| void | selectFdClr (fd_set *fds, int_t s) |
| Remove a descriptor from an existing set. | |
| int_t | selectFdIsSet (fd_set *fds, int_t s) |
| Check whether a descriptor is set. | |
| int_t | gethostbyname (const char_t *name, hostent *info) |
| Retrieve host address corresponding to a host name. | |
| in_addr_t | inet_addr (const char_t *cp) |
| Convert a dot-decimal string into binary data in network byte order. | |
| int_t | inet_aton (const char_t *cp, in_addr *inp) |
| Convert a dot-decimal string into binary form. | |
| const char_t * | inet_ntoa (in_addr in, char_t *cp) |
| Convert a binary IPv4 address to dot-decimal notation. | |
| int_t | inet_pton (int_t af, const char_t *src, void *dst) |
| Convert an IPv4 or IPv6 address from text to binary form. | |
| const char_t * | inet_ntop (int_t af, const void *src, char_t *dst, socklen_t size) |
| Convert an IPv4 or IPv6 address from binary to text. | |
Detailed Description
BSD socket API.
License
Copyright (C) 2010-2017 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:
- 1.7.6
Definition in file bsd_socket.c.
Function Documentation
Permit an incoming connection attempt on a socket.
- Parameters:
-
[in] s Descriptor that identifies a socket in the listening state [out] addr Address of the connecting entity (optional) [in,out] addrlen Length in bytes of the address (optional)
- Returns:
- If no error occurs, accept returns a descriptor for the new socket. Otherwise, it returns SOCKET_ERROR
Definition at line 389 of file bsd_socket.c.
Associate a local address with a socket.
- Parameters:
-
[in] s Descriptor identifying an unbound socket [in] addr Local address to assign to the bound socket [in] addrlen Length in bytes of the address
- Returns:
- If no error occurs, bind returns SOCKET_SUCCESS. Otherwise, it returns SOCKET_ERROR
Definition at line 148 of file bsd_socket.c.
| int_t closesocket | ( | int_t | s ) |
The closesocket function closes an existing socket.
- Parameters:
-
[in] s Descriptor that identifies a socket
- Returns:
- If no error occurs, closesocket returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 1490 of file bsd_socket.c.
Establish a connection to a specified socket.
- Parameters:
-
[in] s Descriptor identifying an unconnected socket [in] addr Address to which the connection should be established [in] addrlen Length in bytes of the address
- Returns:
- If no error occurs, connect returns SOCKET_SUCCESS. Otherwise, it returns SOCKET_ERROR
Definition at line 249 of file bsd_socket.c.
| int_t fcntl | ( | int_t | s, |
| int_t | cmd, | ||
| void * | arg | ||
| ) |
Perform specific operation.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] cmd A command to perform on the socket [in,out] arg A pointer to a parameter
- Returns:
- If no error occurs, setsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 1379 of file bsd_socket.c.
| int_t gethostbyname | ( | const char_t * | name, |
| hostent * | info | ||
| ) |
Retrieve host address corresponding to a host name.
- Parameters:
-
[in] name Name of the host to resolve [out] info Address of the specified host
- Returns:
- If no error occurs, gethostbyname returns 0. Otherwise it returns an appropriate error code
Definition at line 1797 of file bsd_socket.c.
Retrieves the address of the peer to which a socket is connected.
- Parameters:
-
[in] s Descriptor identifying a socket [out] addr Address of the peer [in,out] addrlen Length in bytes of the address
- Returns:
- If no error occurs, getpeername returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 881 of file bsd_socket.c.
Retrieves the local name for a socket.
- Parameters:
-
[in] s Descriptor identifying a socket [out] addr Address of the socket [in,out] addrlen Length in bytes of the address
- Returns:
- If no error occurs, getsockname returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 789 of file bsd_socket.c.
| int_t getsockopt | ( | int_t | s, |
| int_t | level, | ||
| int_t | optname, | ||
| void * | optval, | ||
| socklen_t * | optlen | ||
| ) |
The getsockopt function retrieves a socket option.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] level The level at which the option is defined [in] optname The socket option for which the value is to be retrieved [out] optval A pointer to the buffer in which the value for the requested option is to be returned [in,out] optlen The size, in bytes, of the buffer pointed to by the optval parameter
- Returns:
- If no error occurs, getsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 1125 of file bsd_socket.c.
| in_addr_t inet_addr | ( | const char_t * | cp ) |
Convert a dot-decimal string into binary data in network byte order.
- Parameters:
-
[in] cp NULL-terminated string representing the IPv4 address
- Returns:
- Binary data in network byte order
Definition at line 1853 of file bsd_socket.c.
| int_t inet_aton | ( | const char_t * | cp, |
| in_addr * | inp | ||
| ) |
Convert a dot-decimal string into binary form.
- Parameters:
-
[in] cp NULL-terminated string representing the IPv4 address [out] inp Binary data in network byte order
- Returns:
- The function returns non-zero if the address is valid, zero if not
Definition at line 1887 of file bsd_socket.c.
| const char_t* inet_ntoa | ( | in_addr | in, |
| char_t * | cp | ||
| ) |
Convert a binary IPv4 address to dot-decimal notation.
- Parameters:
-
[in] in Binary representation of the IPv4 address [out] cp Pointer to the buffer where to format the string
- Returns:
- Pointer to the formatted string
Definition at line 1923 of file bsd_socket.c.
| const char_t* inet_ntop | ( | int_t | af, |
| const void * | src, | ||
| char_t * | dst, | ||
| socklen_t | size | ||
| ) |
Convert an IPv4 or IPv6 address from binary to text.
- Parameters:
-
[in] af Address family [in] src Binary representation of the IP address [out] dst NULL-terminated string representing the IP address [in] size Number of bytes available in the buffer
- Returns:
- On success, the function returns a pointer to the formatted string. NULL is returned if there was an error
Definition at line 2018 of file bsd_socket.c.
| int_t inet_pton | ( | int_t | af, |
| const char_t * | src, | ||
| void * | dst | ||
| ) |
Convert an IPv4 or IPv6 address from text to binary form.
- Parameters:
-
[in] af Address family [in] src NULL-terminated string representing the IP address [out] dst Binary representation of the IP address
- Returns:
- The function returns 1 on success. 0 is returned if the address is not valid. If the address family is not valid, -1 is returned
Definition at line 1946 of file bsd_socket.c.
| int_t ioctlsocket | ( | int_t | s, |
| uint32_t | cmd, | ||
| void * | arg | ||
| ) |
Control the I/O mode of a socket.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] cmd A command to perform on the socket [in,out] arg A pointer to a parameter
- Returns:
- If no error occurs, setsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 1302 of file bsd_socket.c.
| int_t listen | ( | int_t | s, |
| int_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] s Descriptor identifying a bound, unconnected socket [in] backlog Maximum length of the queue of pending connections
- Returns:
- If no error occurs, listen returns SOCKET_SUCCESS. Otherwise, it returns SOCKET_ERROR
Definition at line 351 of file bsd_socket.c.
| int_t recv | ( | int_t | s, |
| void * | data, | ||
| size_t | size, | ||
| int_t | flags | ||
| ) |
Receive data from a connected socket.
- Parameters:
-
[in] s Descriptor that identifies a connected socket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [in] flags Set of flags that influences the behavior of this function
- Returns:
- If no error occurs, recv returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned
Definition at line 645 of file bsd_socket.c.
| int_t recvfrom | ( | int_t | s, |
| void * | data, | ||
| size_t | size, | ||
| int_t | flags, | ||
| sockaddr * | addr, | ||
| socklen_t * | addrlen | ||
| ) |
Receive a datagram.
- Parameters:
-
[in] s Descriptor that identifies a socket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [in] flags Set of flags that influences the behavior of this function [out] addr Source address upon return (optional) [in,out] addrlen Length in bytes of the address (optional)
- Returns:
- If no error occurs, recvfrom returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned
Definition at line 694 of file bsd_socket.c.
| int_t select | ( | int_t | nfds, |
| fd_set * | readfds, | ||
| fd_set * | writefds, | ||
| fd_set * | exceptfds, | ||
| const timeval * | timeout | ||
| ) |
Determine the status of one or more sockets.
The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O
- Parameters:
-
[in] nfds Unused parameter included only for compatibility with Berkeley socket [in,out] readfds An optional pointer to a set of sockets to be checked for readability [in,out] writefds An optional pointer to a set of sockets to be checked for writability [in,out] exceptfds An optional pointer to a set of sockets to be checked for errors [in] timeout The maximum time for select to wait. Set the timeout parameter to null for blocking operations
- Returns:
- The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred
Definition at line 1528 of file bsd_socket.c.
| void selectFdClr | ( | fd_set * | fds, |
| int_t | s | ||
| ) |
Remove a descriptor from an existing set.
- Parameters:
-
[in] fds Pointer to a descriptor set [in] s Descriptor that identifies the socket to remove
Definition at line 1740 of file bsd_socket.c.
| int_t selectFdIsSet | ( | fd_set * | fds, |
| int_t | s | ||
| ) |
Check whether a descriptor is set.
- Parameters:
-
[in] fds Pointer to a descriptor set [in] s Descriptor that identifies the socket to test
- Returns:
- Nonzero if s is a member of the set. Otherwise, zero
Definition at line 1772 of file bsd_socket.c.
| void selectFdSet | ( | fd_set * | fds, |
| int_t | s | ||
| ) |
Add a descriptor to an existing set.
- Parameters:
-
[in] fds Pointer to a descriptor set [in] s Descriptor that identifies the socket to add
Definition at line 1711 of file bsd_socket.c.
| void selectFdZero | ( | fd_set * | fds ) |
Initializes a descriptor set.
- Parameters:
-
[in] fds Pointer to a descriptor set
Definition at line 1698 of file bsd_socket.c.
| int_t send | ( | int_t | s, |
| const void * | data, | ||
| size_t | length, | ||
| int_t | flags | ||
| ) |
Send data to a connected socket.
- Parameters:
-
[in] s Descriptor that identifies a connected socket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of bytes to be transmitted [in] flags Set of flags that influences the behavior of this function
- Returns:
- If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the length parameter. Otherwise, a value of SOCKET_ERROR is returned
Definition at line 481 of file bsd_socket.c.
| int_t sendto | ( | int_t | s, |
| const void * | data, | ||
| size_t | length, | ||
| int_t | flags, | ||
| const sockaddr * | addr, | ||
| socklen_t | addrlen | ||
| ) |
Send a datagram to a specific destination.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of bytes to be transmitted [in] flags Set of flags that influences the behavior of this function [in] addr Destination address [in] addrlen Length in bytes of the destination address
- Returns:
- If no error occurs, sendto returns the total number of bytes sent, which can be less than the number requested to be sent in the length parameter. Otherwise, a value of SOCKET_ERROR is returned
Definition at line 540 of file bsd_socket.c.
| int_t setsockopt | ( | int_t | s, |
| int_t | level, | ||
| int_t | optname, | ||
| const void * | optval, | ||
| socklen_t | optlen | ||
| ) |
The setsockopt function sets a socket option.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] level The level at which the option is defined [in] optname The socket option for which the value is to be set [in] optval A pointer to the buffer in which the value for the requested option is specified [in] optlen The size, in bytes, of the buffer pointed to by the optval parameter
- Returns:
- If no error occurs, setsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 975 of file bsd_socket.c.
| int_t shutdown | ( | int_t | s, |
| int_t | how | ||
| ) |
The shutdown function disables sends or receives on a socket.
- Parameters:
-
[in] s Descriptor that identifies a socket [in] how A flag that describes what types of operation will no longer be allowed
- Returns:
- If no error occurs, shutdown returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR
Definition at line 1454 of file bsd_socket.c.
| int_t socket | ( | int_t | family, |
| int_t | type, | ||
| int_t | protocol | ||
| ) |
Create a socket that is bound to a specific transport service provider.
- Parameters:
-
[in] family Address family [in] type Type specification for the new socket [in] protocol Protocol to be used
- Returns:
- On success, a file descriptor for the new socket is returned. On failure, SOCKET_ERROR is returned
Definition at line 106 of file bsd_socket.c.
| int_t socketTranslateErrorCode | ( | error_t | error ) |
Translate error code.
- Parameters:
-
[in] error Error code to be translated
- Returns:
- BSD error code
Definition at line 56 of file bsd_socket.c.
Generated on Tue Jul 12 2022 17:10:18 by
1.7.2