bsd_socket.h File Reference

BSD socket API. More...

#include "os_port.h"

Go to the source code of this file.

Data Structures

struct  sockaddr
 Socket address. More...
 
struct  in_addr
 Structure that represents an IPv4 address. More...
 
struct  sockaddr_in
 IPv4 address information. More...
 
struct  in6_addr
 Structure that represents an IPv6 address. More...
 
struct  sockaddr_in6
 IPv6 address information. More...
 
struct  fd_set
 Set of sockets. More...
 
struct  timeval
 Timeout structure. More...
 
struct  hostent
 Information about a given host. More...
 

Macros

#define BSD_SOCKET_SUPPORT   ENABLED
 
#define AF_INET   2
 
#define AF_INET6   10
 
#define AF_PACKET   17
 
#define SOCK_STREAM   1
 
#define SOCK_DGRAM   2
 
#define SOCK_RAW   3
 
#define IPPROTO_ICMP   1
 
#define IPPROTO_IGMP   2
 
#define IPPROTO_TCP   6
 
#define IPPROTO_UDP   17
 
#define IPPROTO_ICMPV6   58
 
#define ETH_P_ALL   0x0000
 
#define ETH_P_IP   0x0800
 
#define ETH_P_ARP   0x0806
 
#define ETH_P_IPV6   0x86DD
 
#define SOL_SOCKET   0xFFFF
 
#define INADDR_ANY   0x00000000
 
#define INADDR_LOOPBACK   0x7F000001
 
#define INADDR_BROADCAST   0xFFFFFFFF
 
#define MSG_PEEK   0x02
 
#define MSG_DONTROUTE   0x04
 
#define MSG_WAITALL   0x08
 
#define MSG_DONTWAIT   0x01
 
#define SD_RECEIVE   0
 
#define SD_SEND   1
 
#define SD_BOTH   2
 
#define SO_REUSEADDR   0x0004
 
#define SO_KEEPALIVE   0x0008
 
#define SO_DONTROUTE   0x0010
 
#define SO_BROADCAST   0x0020
 
#define SO_LINGER   0x0080
 
#define SO_SNDBUF   0x1001
 
#define SO_RCVBUF   0x1002
 
#define SO_SNDTIMEO   0x1005
 
#define SO_RCVTIMEO   0x1006
 
#define SO_ERROR   0x1007
 
#define SO_TYPE   0x1008
 
#define SO_MAX_MSG_SIZE   0x2003
 
#define SO_BINDTODEVICE   0x3000
 
#define TCP_NODELAY   0x0001
 
#define FIONREAD   0x400466FF
 
#define FIONBIO   0x800466FE
 
#define F_GETFL   3
 
#define F_SETFL   4
 
#define O_NONBLOCK   0x0004
 
#define SOCKET_SUCCESS   0
 
#define SOCKET_ERROR   (-1)
 
#define EAGAIN   11
 
#define EWOULDBLOCK   11
 
#define EFAULT   14
 
#define EINVAL   22
 
#define ENOPROTOOPT   92
 
#define ECONNRESET   104
 
#define EISCONN   106
 
#define ENOTCONN   107
 
#define ESHUTDOWN   108
 
#define ECONNREFUSED   111
 
#define INADDR_NONE   ((in_addr_t) (-1))
 
#define FD_SETSIZE   8
 
#define FD_ZERO(fds)   selectFdZero(fds)
 
#define FD_SET(s, fds)   selectFdSet(fds, s)
 
#define FD_CLR(s, fds)   selectFdClr(fds, s)
 
#define FD_ISSET(s, fds)   selectFdIsSet(fds, s)
 

Typedefs

typedef int_t socklen_t
 Length type. More...
 
typedef uint32_t in_addr_t
 IPv4 address. More...
 
typedef struct sockaddr sockaddr
 Socket address. More...
 
typedef struct in_addr in_addr
 Structure that represents an IPv4 address. More...
 
typedef struct sockaddr_in sockaddr_in
 IPv4 address information. More...
 
typedef struct in6_addr in6_addr
 Structure that represents an IPv6 address. More...
 
typedef struct sockaddr_in6 sockaddr_in6
 IPv6 address information. More...
 
typedef struct fd_set fd_set
 Set of sockets. More...
 
typedef struct timeval timeval
 Timeout structure. More...
 
typedef struct hostent hostent
 Information about a given host. More...
 

Functions

int_t socket (int_t family, int_t type, int_t protocol)
 Create a socket that is bound to a specific transport service provider. More...
 
int_t bind (int_t s, const sockaddr *addr, socklen_t addrlen)
 Associate a local address with a socket. More...
 
int_t connect (int_t s, const sockaddr *addr, socklen_t addrlen)
 Establish a connection to a specified socket. More...
 
int_t listen (int_t s, int_t backlog)
 Place a socket in the listening state. More...
 
int_t accept (int_t s, sockaddr *addr, socklen_t *addrlen)
 Permit an incoming connection attempt on a socket. More...
 
int_t send (int_t s, const void *data, size_t length, int_t flags)
 Send data to a connected socket. More...
 
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. More...
 
int_t recv (int_t s, void *data, size_t size, int_t flags)
 Receive data from a connected socket. More...
 
int_t recvfrom (int_t s, void *data, size_t size, int_t flags, sockaddr *addr, socklen_t *addrlen)
 Receive a datagram. More...
 
int_t getsockname (int_t s, sockaddr *addr, socklen_t *addrlen)
 Retrieves the local name for a socket. More...
 
int_t getpeername (int_t s, sockaddr *addr, socklen_t *addrlen)
 Retrieves the address of the peer to which a socket is connected. More...
 
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. More...
 
int_t getsockopt (int_t s, int_t level, int_t optname, void *optval, socklen_t *optlen)
 The getsockopt function retrieves a socket option. More...
 
int_t ioctlsocket (int_t s, uint32_t cmd, void *arg)
 Control the I/O mode of a socket. More...
 
int_t fcntl (int_t s, int_t cmd, void *arg)
 Perform specific operation. More...
 
int_t shutdown (int_t s, int_t how)
 The shutdown function disables sends or receives on a socket. More...
 
int_t closesocket (int_t s)
 The closesocket function closes an existing socket. More...
 
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. More...
 
void selectFdZero (fd_set *fds)
 Initializes a descriptor set. More...
 
void selectFdSet (fd_set *fds, int_t s)
 Add a descriptor to an existing set. More...
 
void selectFdClr (fd_set *fds, int_t s)
 Remove a descriptor from an existing set. More...
 
int_t selectFdIsSet (fd_set *fds, int_t s)
 Check whether a descriptor is set. More...
 
int_t gethostbyname (const char_t *name, hostent *info)
 Retrieve host address corresponding to a host name. More...
 
in_addr_t inet_addr (const char_t *cp)
 Convert a dot-decimal string into binary data in network byte order. More...
 
int_t inet_aton (const char_t *cp, in_addr *inp)
 Convert a dot-decimal string into binary form. More...
 
const char_tinet_ntoa (in_addr in, char_t *cp)
 Convert a binary IPv4 address to dot-decimal notation. More...
 
int_t inet_pton (int_t af, const char_t *src, void *dst)
 Convert an IPv4 or IPv6 address from text to binary form. More...
 
const char_tinet_ntop (int_t af, const void *src, char_t *dst, socklen_t size)
 Convert an IPv4 or IPv6 address from binary to text. More...
 

Variables

const in6_addr in6addr_any
 
const in6_addr in6addr_loopback
 

Detailed Description

BSD socket API.

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file bsd_socket.h.

Macro Definition Documentation

◆ AF_INET

#define AF_INET   2

Definition at line 64 of file bsd_socket.h.

◆ AF_INET6

#define AF_INET6   10

Definition at line 65 of file bsd_socket.h.

◆ AF_PACKET

#define AF_PACKET   17

Definition at line 66 of file bsd_socket.h.

◆ BSD_SOCKET_SUPPORT

#define BSD_SOCKET_SUPPORT   ENABLED

Definition at line 34 of file bsd_socket.h.

◆ EAGAIN

#define EAGAIN   11

Definition at line 139 of file bsd_socket.h.

◆ ECONNREFUSED

#define ECONNREFUSED   111

Definition at line 148 of file bsd_socket.h.

◆ ECONNRESET

#define ECONNRESET   104

Definition at line 144 of file bsd_socket.h.

◆ EFAULT

#define EFAULT   14

Definition at line 141 of file bsd_socket.h.

◆ EINVAL

#define EINVAL   22

Definition at line 142 of file bsd_socket.h.

◆ EISCONN

#define EISCONN   106

Definition at line 145 of file bsd_socket.h.

◆ ENOPROTOOPT

#define ENOPROTOOPT   92

Definition at line 143 of file bsd_socket.h.

◆ ENOTCONN

#define ENOTCONN   107

Definition at line 146 of file bsd_socket.h.

◆ ESHUTDOWN

#define ESHUTDOWN   108

Definition at line 147 of file bsd_socket.h.

◆ ETH_P_ALL

#define ETH_P_ALL   0x0000

Definition at line 81 of file bsd_socket.h.

◆ ETH_P_ARP

#define ETH_P_ARP   0x0806

Definition at line 83 of file bsd_socket.h.

◆ ETH_P_IP

#define ETH_P_IP   0x0800

Definition at line 82 of file bsd_socket.h.

◆ ETH_P_IPV6

#define ETH_P_IPV6   0x86DD

Definition at line 84 of file bsd_socket.h.

◆ EWOULDBLOCK

#define EWOULDBLOCK   11

Definition at line 140 of file bsd_socket.h.

◆ F_GETFL

#define F_GETFL   3

Definition at line 128 of file bsd_socket.h.

◆ F_SETFL

#define F_SETFL   4

Definition at line 129 of file bsd_socket.h.

◆ FD_CLR

#define FD_CLR (   s,
  fds 
)    selectFdClr(fds, s)

Definition at line 157 of file bsd_socket.h.

◆ FD_ISSET

#define FD_ISSET (   s,
  fds 
)    selectFdIsSet(fds, s)

Definition at line 158 of file bsd_socket.h.

◆ FD_SET

#define FD_SET (   s,
  fds 
)    selectFdSet(fds, s)

Definition at line 156 of file bsd_socket.h.

◆ FD_SETSIZE

#define FD_SETSIZE   8

Definition at line 154 of file bsd_socket.h.

◆ FD_ZERO

#define FD_ZERO (   fds)    selectFdZero(fds)

Definition at line 155 of file bsd_socket.h.

◆ FIONBIO

#define FIONBIO   0x800466FE

Definition at line 125 of file bsd_socket.h.

◆ FIONREAD

#define FIONREAD   0x400466FF

Definition at line 124 of file bsd_socket.h.

◆ INADDR_ANY

#define INADDR_ANY   0x00000000

Definition at line 90 of file bsd_socket.h.

◆ INADDR_BROADCAST

#define INADDR_BROADCAST   0xFFFFFFFF

Definition at line 92 of file bsd_socket.h.

◆ INADDR_LOOPBACK

#define INADDR_LOOPBACK   0x7F000001

Definition at line 91 of file bsd_socket.h.

◆ INADDR_NONE

#define INADDR_NONE   ((in_addr_t) (-1))

Definition at line 151 of file bsd_socket.h.

◆ IPPROTO_ICMP

#define IPPROTO_ICMP   1

Definition at line 74 of file bsd_socket.h.

◆ IPPROTO_ICMPV6

#define IPPROTO_ICMPV6   58

Definition at line 78 of file bsd_socket.h.

◆ IPPROTO_IGMP

#define IPPROTO_IGMP   2

Definition at line 75 of file bsd_socket.h.

◆ IPPROTO_TCP

#define IPPROTO_TCP   6

Definition at line 76 of file bsd_socket.h.

◆ IPPROTO_UDP

#define IPPROTO_UDP   17

Definition at line 77 of file bsd_socket.h.

◆ MSG_DONTROUTE

#define MSG_DONTROUTE   0x04

Definition at line 96 of file bsd_socket.h.

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   0x01

Definition at line 98 of file bsd_socket.h.

◆ MSG_PEEK

#define MSG_PEEK   0x02

Definition at line 95 of file bsd_socket.h.

◆ MSG_WAITALL

#define MSG_WAITALL   0x08

Definition at line 97 of file bsd_socket.h.

◆ O_NONBLOCK

#define O_NONBLOCK   0x0004

Definition at line 132 of file bsd_socket.h.

◆ SD_BOTH

#define SD_BOTH   2

Definition at line 103 of file bsd_socket.h.

◆ SD_RECEIVE

#define SD_RECEIVE   0

Definition at line 101 of file bsd_socket.h.

◆ SD_SEND

#define SD_SEND   1

Definition at line 102 of file bsd_socket.h.

◆ SO_BINDTODEVICE

#define SO_BINDTODEVICE   0x3000

Definition at line 118 of file bsd_socket.h.

◆ SO_BROADCAST

#define SO_BROADCAST   0x0020

Definition at line 109 of file bsd_socket.h.

◆ SO_DONTROUTE

#define SO_DONTROUTE   0x0010

Definition at line 108 of file bsd_socket.h.

◆ SO_ERROR

#define SO_ERROR   0x1007

Definition at line 115 of file bsd_socket.h.

◆ SO_KEEPALIVE

#define SO_KEEPALIVE   0x0008

Definition at line 107 of file bsd_socket.h.

◆ SO_LINGER

#define SO_LINGER   0x0080

Definition at line 110 of file bsd_socket.h.

◆ SO_MAX_MSG_SIZE

#define SO_MAX_MSG_SIZE   0x2003

Definition at line 117 of file bsd_socket.h.

◆ SO_RCVBUF

#define SO_RCVBUF   0x1002

Definition at line 112 of file bsd_socket.h.

◆ SO_RCVTIMEO

#define SO_RCVTIMEO   0x1006

Definition at line 114 of file bsd_socket.h.

◆ SO_REUSEADDR

#define SO_REUSEADDR   0x0004

Definition at line 106 of file bsd_socket.h.

◆ SO_SNDBUF

#define SO_SNDBUF   0x1001

Definition at line 111 of file bsd_socket.h.

◆ SO_SNDTIMEO

#define SO_SNDTIMEO   0x1005

Definition at line 113 of file bsd_socket.h.

◆ SO_TYPE

#define SO_TYPE   0x1008

Definition at line 116 of file bsd_socket.h.

◆ SOCK_DGRAM

#define SOCK_DGRAM   2

Definition at line 70 of file bsd_socket.h.

◆ SOCK_RAW

#define SOCK_RAW   3

Definition at line 71 of file bsd_socket.h.

◆ SOCK_STREAM

#define SOCK_STREAM   1

Definition at line 69 of file bsd_socket.h.

◆ SOCKET_ERROR

#define SOCKET_ERROR   (-1)

Definition at line 136 of file bsd_socket.h.

◆ SOCKET_SUCCESS

#define SOCKET_SUCCESS   0

Definition at line 135 of file bsd_socket.h.

◆ SOL_SOCKET

#define SOL_SOCKET   0xFFFF

Definition at line 87 of file bsd_socket.h.

◆ TCP_NODELAY

#define TCP_NODELAY   0x0001

Definition at line 121 of file bsd_socket.h.

Typedef Documentation

◆ fd_set

typedef struct fd_set fd_set

Set of sockets.

◆ hostent

typedef struct hostent hostent

Information about a given host.

◆ in6_addr

typedef struct in6_addr in6_addr

Structure that represents an IPv6 address.

◆ in_addr

typedef struct in_addr in_addr

Structure that represents an IPv4 address.

◆ in_addr_t

typedef uint32_t in_addr_t

IPv4 address.

Definition at line 177 of file bsd_socket.h.

◆ sockaddr

typedef struct sockaddr sockaddr

Socket address.

◆ sockaddr_in

typedef struct sockaddr_in sockaddr_in

IPv4 address information.

◆ sockaddr_in6

typedef struct sockaddr_in6 sockaddr_in6

IPv6 address information.

◆ socklen_t

typedef int_t socklen_t

Length type.

Definition at line 170 of file bsd_socket.h.

◆ timeval

typedef struct timeval timeval

Timeout structure.

Function Documentation

◆ accept()

int_t accept ( int_t  s,
sockaddr addr,
socklen_t addrlen 
)

Permit an incoming connection attempt on a socket.

Parameters
[in]sDescriptor that identifies a socket in the listening state
[out]addrAddress of the connecting entity (optional)
[in,out]addrlenLength 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.

◆ bind()

int_t bind ( int_t  s,
const sockaddr addr,
socklen_t  addrlen 
)

Associate a local address with a socket.

Parameters
[in]sDescriptor identifying an unbound socket
[in]addrLocal address to assign to the bound socket
[in]addrlenLength 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.

◆ closesocket()

int_t closesocket ( int_t  s)

The closesocket function closes an existing socket.

Parameters
[in]sDescriptor that identifies a socket
Returns
If no error occurs, closesocket returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR

Definition at line 1494 of file bsd_socket.c.

◆ connect()

int_t connect ( int_t  s,
const sockaddr addr,
socklen_t  addrlen 
)

Establish a connection to a specified socket.

Parameters
[in]sDescriptor identifying an unconnected socket
[in]addrAddress to which the connection should be established
[in]addrlenLength 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.

◆ fcntl()

int_t fcntl ( int_t  s,
int_t  cmd,
void *  arg 
)

Perform specific operation.

Parameters
[in]sDescriptor that identifies a socket
[in]cmdA command to perform on the socket
[in,out]argA pointer to a parameter
Returns
If no error occurs, setsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR

Definition at line 1383 of file bsd_socket.c.

◆ gethostbyname()

int_t gethostbyname ( const char_t name,
hostent info 
)

Retrieve host address corresponding to a host name.

Parameters
[in]nameName of the host to resolve
[out]infoAddress of the specified host
Returns
If no error occurs, gethostbyname returns 0. Otherwise it returns an appropriate error code

Definition at line 1801 of file bsd_socket.c.

◆ getpeername()

int_t getpeername ( int_t  s,
sockaddr addr,
socklen_t addrlen 
)

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

Parameters
[in]sDescriptor identifying a socket
[out]addrAddress of the peer
[in,out]addrlenLength 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.

◆ getsockname()

int_t getsockname ( int_t  s,
sockaddr addr,
socklen_t addrlen 
)

Retrieves the local name for a socket.

Parameters
[in]sDescriptor identifying a socket
[out]addrAddress of the socket
[in,out]addrlenLength 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.

◆ getsockopt()

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]sDescriptor that identifies a socket
[in]levelThe level at which the option is defined
[in]optnameThe socket option for which the value is to be retrieved
[out]optvalA pointer to the buffer in which the value for the requested option is to be returned
[in,out]optlenThe 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.

◆ inet_addr()

in_addr_t inet_addr ( const char_t cp)

Convert a dot-decimal string into binary data in network byte order.

Parameters
[in]cpNULL-terminated string representing the IPv4 address
Returns
Binary data in network byte order

Definition at line 1857 of file bsd_socket.c.

◆ inet_aton()

int_t inet_aton ( const char_t cp,
in_addr inp 
)

Convert a dot-decimal string into binary form.

Parameters
[in]cpNULL-terminated string representing the IPv4 address
[out]inpBinary data in network byte order
Returns
The function returns non-zero if the address is valid, zero if not

Definition at line 1891 of file bsd_socket.c.

◆ inet_ntoa()

const char_t* inet_ntoa ( in_addr  in,
char_t cp 
)

Convert a binary IPv4 address to dot-decimal notation.

Parameters
[in]inBinary representation of the IPv4 address
[out]cpPointer to the buffer where to format the string
Returns
Pointer to the formatted string

Definition at line 1927 of file bsd_socket.c.

◆ inet_ntop()

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]afAddress family
[in]srcBinary representation of the IP address
[out]dstNULL-terminated string representing the IP address
[in]sizeNumber 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 2022 of file bsd_socket.c.

◆ inet_pton()

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]afAddress family
[in]srcNULL-terminated string representing the IP address
[out]dstBinary 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 1950 of file bsd_socket.c.

◆ ioctlsocket()

int_t ioctlsocket ( int_t  s,
uint32_t  cmd,
void *  arg 
)

Control the I/O mode of a socket.

Parameters
[in]sDescriptor that identifies a socket
[in]cmdA command to perform on the socket
[in,out]argA pointer to a parameter
Returns
If no error occurs, setsockopt returns SOCKET_SUCCESS Otherwise, it returns SOCKET_ERROR

Definition at line 1306 of file bsd_socket.c.

◆ listen()

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]sDescriptor identifying a bound, unconnected socket
[in]backlogMaximum 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.

◆ recv()

int_t recv ( int_t  s,
void *  data,
size_t  size,
int_t  flags 
)

Receive data from a connected socket.

Parameters
[in]sDescriptor that identifies a connected socket
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[in]flagsSet 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.

◆ recvfrom()

int_t recvfrom ( int_t  s,
void *  data,
size_t  size,
int_t  flags,
sockaddr addr,
socklen_t addrlen 
)

Receive a datagram.

Parameters
[in]sDescriptor that identifies a socket
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[in]flagsSet of flags that influences the behavior of this function
[out]addrSource address upon return (optional)
[in,out]addrlenLength 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.

◆ select()

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]nfdsUnused parameter included only for compatibility with Berkeley socket
[in,out]readfdsAn optional pointer to a set of sockets to be checked for readability
[in,out]writefdsAn optional pointer to a set of sockets to be checked for writability
[in,out]exceptfdsAn optional pointer to a set of sockets to be checked for errors
[in]timeoutThe 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 1532 of file bsd_socket.c.

◆ selectFdClr()

void selectFdClr ( fd_set fds,
int_t  s 
)

Remove a descriptor from an existing set.

Parameters
[in]fdsPointer to a descriptor set
[in]sDescriptor that identifies the socket to remove

Definition at line 1744 of file bsd_socket.c.

◆ selectFdIsSet()

int_t selectFdIsSet ( fd_set fds,
int_t  s 
)

Check whether a descriptor is set.

Parameters
[in]fdsPointer to a descriptor set
[in]sDescriptor that identifies the socket to test
Returns
Nonzero if s is a member of the set. Otherwise, zero

Definition at line 1776 of file bsd_socket.c.

◆ selectFdSet()

void selectFdSet ( fd_set fds,
int_t  s 
)

Add a descriptor to an existing set.

Parameters
[in]fdsPointer to a descriptor set
[in]sDescriptor that identifies the socket to add

Definition at line 1715 of file bsd_socket.c.

◆ selectFdZero()

void selectFdZero ( fd_set fds)

Initializes a descriptor set.

Parameters
[in]fdsPointer to a descriptor set

Definition at line 1702 of file bsd_socket.c.

◆ send()

int_t send ( int_t  s,
const void *  data,
size_t  length,
int_t  flags 
)

Send data to a connected socket.

Parameters
[in]sDescriptor that identifies a connected socket
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
[in]flagsSet 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.

◆ sendto()

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]sDescriptor that identifies a socket
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
[in]flagsSet of flags that influences the behavior of this function
[in]addrDestination address
[in]addrlenLength 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.

◆ setsockopt()

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]sDescriptor that identifies a socket
[in]levelThe level at which the option is defined
[in]optnameThe socket option for which the value is to be set
[in]optvalA pointer to the buffer in which the value for the requested option is specified
[in]optlenThe 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.

◆ shutdown()

int_t shutdown ( int_t  s,
int_t  how 
)

The shutdown function disables sends or receives on a socket.

Parameters
[in]sDescriptor that identifies a socket
[in]howA 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 1458 of file bsd_socket.c.

◆ socket()

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]familyAddress family
[in]typeType specification for the new socket
[in]protocolProtocol 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.

Variable Documentation

◆ in6addr_any

const in6_addr in6addr_any

Definition at line 43 of file bsd_socket.c.

◆ in6addr_loopback

const in6_addr in6addr_loopback

Definition at line 46 of file bsd_socket.c.