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  sockaddr_storage
 Socket address storage. 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  ip_mreq
 Multicast group information for IPv4 addresses. More...
 
struct  ipv6_mreq
 Multicast group information for IPv6 addresses. More...
 
struct  linger
 Linger structure. More...
 
struct  iovec
 Scatter/gather array. More...
 
struct  msghdr
 Message header. More...
 
struct  cmsghdr
 Ancillary data header. More...
 
struct  in_pktinfo
 IPv4 packet information. More...
 
struct  in6_pktinfo
 IPv6 packet information. More...
 
struct  fd_set
 Set of sockets. More...
 
struct  hostent
 Information about a given host. More...
 
struct  addrinfo
 Information about address of a service provider. More...
 
struct  timeval
 Timeout structure. More...
 

Macros

#define BSD_SOCKET_SUPPORT   ENABLED
 
#define FD_SETSIZE   8
 
#define BSD_SOCKET_SET_ERRNO(e)
 
#define AF_UNSPEC   0
 
#define AF_INET   2
 
#define AF_INET6   10
 
#define AF_PACKET   17
 
#define PF_UNSPEC   AF_UNSPEC
 
#define PF_INET   AF_INET
 
#define PF_INET6   AF_INET6
 
#define PF_PACKET   AF_PACKET
 
#define SOCK_STREAM   1
 
#define SOCK_DGRAM   2
 
#define SOCK_RAW   3
 
#define IPPROTO_IP   0
 
#define IPPROTO_ICMP   1
 
#define IPPROTO_IGMP   2
 
#define IPPROTO_TCP   6
 
#define IPPROTO_UDP   17
 
#define IPPROTO_IPV6   41
 
#define IPPROTO_ESP   50
 
#define IPPROTO_AH   51
 
#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   0x0002
 
#define MSG_DONTROUTE   0x0004
 
#define MSG_CTRUNC   0x0008
 
#define MSG_DONTWAIT   0x0040
 
#define MSG_WAITALL   0x0100
 
#define SD_RECEIVE   0
 
#define SD_SEND   1
 
#define SD_BOTH   2
 
#define SHUT_RD   SD_RECEIVE
 
#define SHUT_WR   SD_SEND
 
#define SHUT_RDWR   SD_BOTH
 
#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 IP_TOS   1
 
#define IP_TTL   2
 
#define IP_ROUTER_ALERT   5
 
#define IP_PKTINFO   8
 
#define IP_RECVTTL   12
 
#define IP_RECVTOS   13
 
#define IP_MULTICAST_IF   32
 
#define IP_MULTICAST_TTL   33
 
#define IP_MULTICAST_LOOP   34
 
#define IP_ADD_MEMBERSHIP   35
 
#define IP_DROP_MEMBERSHIP   36
 
#define IP_DONTFRAG   67
 
#define IPV6_UNICAST_HOPS   16
 
#define IPV6_MULTICAST_IF   17
 
#define IPV6_MULTICAST_HOPS   18
 
#define IPV6_MULTICAST_LOOP   19
 
#define IPV6_ADD_MEMBERSHIP   20
 
#define IPV6_DROP_MEMBERSHIP   21
 
#define IPV6_V6ONLY   26
 
#define IPV6_PKTINFO   50
 
#define IPV6_RECVHOPLIMIT   51
 
#define IPV6_HOPLIMIT   52
 
#define IPV6_DONTFRAG   62
 
#define IPV6_RECVTCLASS   66
 
#define IPV6_TCLASS   67
 
#define TCP_NODELAY   0x0001
 
#define TCP_MAXSEG   0x0002
 
#define TCP_KEEPIDLE   0x0004
 
#define TCP_KEEPINTVL   0x0005
 
#define TCP_KEEPCNT   0x0006
 
#define IPTOS_LOWDELAY   0x10
 
#define IPTOS_THROUGHPUT   0x08
 
#define IPTOS_RELIABILITY   0x04
 
#define FIONBIO   126
 
#define FIONREAD   127
 
#define FIONWRITE   121
 
#define FIONSPACE   120
 
#define F_GETFL   3
 
#define F_SETFL   4
 
#define O_NONBLOCK   0x0004
 
#define AI_PASSIVE   0x01
 
#define AI_CANONNAME   0x02
 
#define AI_NUMERICHOST   0x04
 
#define AI_NUMERICSERV   0x08
 
#define AI_ALL   0x10
 
#define AI_ADDRCONFIG   0x20
 
#define AI_V4MAPPED   0x40
 
#define NI_NOFQDN   0x01
 
#define NI_NUMERICHOST   0x02
 
#define NI_NAMEREQD   0x04
 
#define NI_NUMERICSERV   0x08
 
#define NI_DGRAM   0x10
 
#define SOCKET_SUCCESS   0
 
#define SOCKET_ERROR   (-1)
 
#define EAI_ADDRFAMILY   1
 
#define EAI_AGAIN   2
 
#define EAI_BADFLAGS   3
 
#define EAI_FAIL   4
 
#define EAI_FAMILY   5
 
#define EAI_MEMORY   6
 
#define EAI_NODATA   7
 
#define EAI_NONAME   8
 
#define EAI_SERVICE   9
 
#define EAI_SOCKTYPE   10
 
#define EAI_SYSTEM   11
 
#define EAI_OVERFLOW   12
 
#define EINTR   4
 
#define EAGAIN   11
 
#define EWOULDBLOCK   11
 
#define EFAULT   14
 
#define EINVAL   22
 
#define EINPROGRESS   36
 
#define ETIMEDOUT   60
 
#define ENAMETOOLONG   63
 
#define EMSGSIZE   90
 
#define ENOPROTOOPT   92
 
#define ECONNRESET   104
 
#define EISCONN   106
 
#define ENOTCONN   107
 
#define ESHUTDOWN   108
 
#define ECONNREFUSED   111
 
#define NETDB_SUCCESS   0
 
#define HOST_NOT_FOUND   1
 
#define TRY_AGAIN   2
 
#define NO_RECOVERY   3
 
#define NO_ADDRESS   4
 
#define INADDR_NONE   ((in_addr_t) (-1))
 
#define INET_ADDRSTRLEN   16
 
#define INET6_ADDRSTRLEN   40
 
#define CMSG_DATA(cmsg)   ((uint8_t *) (cmsg) + sizeof(struct cmsghdr))
 
#define CMSG_ALIGN(len)   (((len) + sizeof(int_t) - 1) & ~(sizeof(int_t) - 1))
 
#define CMSG_SPACE(len)   (sizeof(struct cmsghdr) + CMSG_ALIGN(len))
 
#define CMSG_LEN(len)   (sizeof(struct cmsghdr) + (len))
 
#define CMSG_FIRSTHDR(msg)   socketCmsgFirstHdr(msg)
 
#define CMSG_NXTHDR(msg, cmsg)   socketCmsgNextHdr(msg, cmsg)
 
#define FD_ZERO(fds)   socketFdZero(fds)
 
#define FD_SET(s, fds)   socketFdSet(fds, s)
 
#define FD_CLR(s, fds)   socketFdClr(fds, s)
 
#define FD_ISSET(s, fds)   socketFdIsSet(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 sockaddrPSOCKADDR
 
typedef struct sockaddr_storage SOCKADDR_STORAGE
 Socket address storage. More...
 
typedef struct sockaddr_storagePSOCKADDR_STORAGE
 
typedef struct in_addr IN_ADDR
 Structure that represents an IPv4 address. More...
 
typedef struct in_addrPIN_ADDR
 
typedef struct sockaddr_in SOCKADDR_IN
 IPv4 address information. More...
 
typedef struct sockaddr_inPSOCKADDR_IN
 
typedef struct in6_addr IN6_ADDR
 Structure that represents an IPv6 address. More...
 
typedef struct in6_addrPIN6_ADDR
 
typedef struct sockaddr_in6 SOCKADDR_IN6
 IPv6 address information. More...
 
typedef struct sockaddr_in6PSOCKADDR_IN6
 
typedef struct ip_mreq IP_MREQ
 Multicast group information for IPv4 addresses. More...
 
typedef struct ip_mreqPIP_MREQ
 
typedef struct ipv6_mreq IPV6_MREQ
 Multicast group information for IPv6 addresses. More...
 
typedef struct ipv6_mreqPIPV6_MREQ
 
typedef struct linger LINGER
 Linger structure. More...
 
typedef struct lingerPLINGER
 
typedef struct msghdr MSGHDR
 Message header. More...
 
typedef struct msghdrPMSGHDR
 
typedef struct cmsghdr CMSGHDR
 Ancillary data header. More...
 
typedef struct cmsghdrPCMSGHDR
 
typedef struct in_pktinfo IN_PKTINFO
 IPv4 packet information. More...
 
typedef struct in_pktinfoPIN_PKTINFO
 
typedef struct in6_pktinfo IN6_PKTINFO
 IPv6 packet information. More...
 
typedef struct in6_pktinfoPIN6_PKTINFO
 
typedef struct fd_set fd_set
 Set of sockets. More...
 
typedef struct fd_set FD_SET
 
typedef struct fd_setPFD_SET
 
typedef struct hostent HOSTENT
 Information about a given host. More...
 
typedef struct hostentPHOSTENT
 
typedef struct addrinfo ADDRINFO
 Information about address of a service provider. More...
 
typedef struct addrinfoPADDRINFO
 
typedef struct timeval TIMEVAL
 Timeout structure. More...
 
typedef struct timevalPTIMEVAL
 

Functions

struct cmsghdrsocketCmsgFirstHdr (struct msghdr *msg)
 Get first ancillary data header. More...
 
struct cmsghdrsocketCmsgNextHdr (struct msghdr *msg, struct cmsghdr *cmsg)
 Get next ancillary data header. More...
 
void socketFdZero (fd_set *fds)
 Initializes a descriptor set. More...
 
void socketFdSet (fd_set *fds, int_t s)
 Add a descriptor to an existing set. More...
 
void socketFdClr (fd_set *fds, int_t s)
 Remove a descriptor from an existing set. More...
 
int_t socketFdIsSet (fd_set *fds, int_t s)
 Check whether a descriptor is set. More...
 
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 struct sockaddr *addr, socklen_t addrlen)
 Associate a local address with a socket. More...
 
int_t connect (int_t s, const struct 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, struct 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 struct sockaddr *addr, socklen_t addrlen)
 Send a datagram to a specific destination. More...
 
int_t sendmsg (int_t s, struct msghdr *msg, int_t flags)
 Send a message. 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, struct sockaddr *addr, socklen_t *addrlen)
 Receive a datagram. More...
 
int_t recvmsg (int_t s, struct msghdr *msg, int_t flags)
 Receive a message. More...
 
int_t getsockname (int_t s, struct sockaddr *addr, socklen_t *addrlen)
 Retrieves the local name for a socket. More...
 
int_t getpeername (int_t s, struct 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, int_t 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 struct timeval *timeout)
 Determine the status of one or more sockets. More...
 
int_t gethostname (char_t *name, size_t len)
 Get system host name. More...
 
struct hostentgethostbyname (const char_t *name)
 Host name resolution. More...
 
struct hostentgethostbyname_r (const char_t *name, struct hostent *result, char_t *buf, size_t buflen, int_t *h_errnop)
 Host name resolution (reentrant version) More...
 
int_t getaddrinfo (const char_t *node, const char_t *service, const struct addrinfo *hints, struct addrinfo **res)
 Convert host and service names to socket address. More...
 
void freeaddrinfo (struct addrinfo *res)
 Free socket address structures. More...
 
int_t getnameinfo (const struct sockaddr *addr, socklen_t addrlen, char_t *host, size_t hostlen, char_t *serv, size_t servlen, int flags)
 Convert a socket address to a corresponding host and service. 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, struct in_addr *inp)
 Convert a dot-decimal string into binary form. More...
 
const char_tinet_ntoa (struct in_addr in)
 Convert a binary IPv4 address to dot-decimal notation. More...
 
const char_tinet_ntoa_r (struct in_addr in, char_t *buf, socklen_t buflen)
 Convert a binary IPv4 address to dot-decimal notation (reentrant version) 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 struct in6_addr in6addr_any
 
const struct in6_addr in6addr_loopback
 

Detailed Description

BSD 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.0

Definition in file bsd_socket.h.

Macro Definition Documentation

◆ AF_INET

#define AF_INET   2

Definition at line 79 of file bsd_socket.h.

◆ AF_INET6

#define AF_INET6   10

Definition at line 80 of file bsd_socket.h.

◆ AF_PACKET

#define AF_PACKET   17

Definition at line 81 of file bsd_socket.h.

◆ AF_UNSPEC

#define AF_UNSPEC   0

Definition at line 78 of file bsd_socket.h.

◆ AI_ADDRCONFIG

#define AI_ADDRCONFIG   0x20

Definition at line 211 of file bsd_socket.h.

◆ AI_ALL

#define AI_ALL   0x10

Definition at line 210 of file bsd_socket.h.

◆ AI_CANONNAME

#define AI_CANONNAME   0x02

Definition at line 207 of file bsd_socket.h.

◆ AI_NUMERICHOST

#define AI_NUMERICHOST   0x04

Definition at line 208 of file bsd_socket.h.

◆ AI_NUMERICSERV

#define AI_NUMERICSERV   0x08

Definition at line 209 of file bsd_socket.h.

◆ AI_PASSIVE

#define AI_PASSIVE   0x01

Definition at line 206 of file bsd_socket.h.

◆ AI_V4MAPPED

#define AI_V4MAPPED   0x40

Definition at line 212 of file bsd_socket.h.

◆ BSD_SOCKET_SET_ERRNO

#define BSD_SOCKET_SET_ERRNO (   e)

Definition at line 50 of file bsd_socket.h.

◆ BSD_SOCKET_SUPPORT

#define BSD_SOCKET_SUPPORT   ENABLED

Definition at line 36 of file bsd_socket.h.

◆ CMSG_ALIGN

#define CMSG_ALIGN (   len)    (((len) + sizeof(int_t) - 1) & ~(sizeof(int_t) - 1))

Definition at line 516 of file bsd_socket.h.

◆ CMSG_DATA

#define CMSG_DATA (   cmsg)    ((uint8_t *) (cmsg) + sizeof(struct cmsghdr))

Definition at line 515 of file bsd_socket.h.

◆ CMSG_FIRSTHDR

#define CMSG_FIRSTHDR (   msg)    socketCmsgFirstHdr(msg)

Definition at line 519 of file bsd_socket.h.

◆ CMSG_LEN

#define CMSG_LEN (   len)    (sizeof(struct cmsghdr) + (len))

Definition at line 518 of file bsd_socket.h.

◆ CMSG_NXTHDR

#define CMSG_NXTHDR (   msg,
  cmsg 
)    socketCmsgNextHdr(msg, cmsg)

Definition at line 520 of file bsd_socket.h.

◆ CMSG_SPACE

#define CMSG_SPACE (   len)    (sizeof(struct cmsghdr) + CMSG_ALIGN(len))

Definition at line 517 of file bsd_socket.h.

◆ EAGAIN

#define EAGAIN   11

Definition at line 241 of file bsd_socket.h.

◆ EAI_ADDRFAMILY

#define EAI_ADDRFAMILY   1

Definition at line 226 of file bsd_socket.h.

◆ EAI_AGAIN

#define EAI_AGAIN   2

Definition at line 227 of file bsd_socket.h.

◆ EAI_BADFLAGS

#define EAI_BADFLAGS   3

Definition at line 228 of file bsd_socket.h.

◆ EAI_FAIL

#define EAI_FAIL   4

Definition at line 229 of file bsd_socket.h.

◆ EAI_FAMILY

#define EAI_FAMILY   5

Definition at line 230 of file bsd_socket.h.

◆ EAI_MEMORY

#define EAI_MEMORY   6

Definition at line 231 of file bsd_socket.h.

◆ EAI_NODATA

#define EAI_NODATA   7

Definition at line 232 of file bsd_socket.h.

◆ EAI_NONAME

#define EAI_NONAME   8

Definition at line 233 of file bsd_socket.h.

◆ EAI_OVERFLOW

#define EAI_OVERFLOW   12

Definition at line 237 of file bsd_socket.h.

◆ EAI_SERVICE

#define EAI_SERVICE   9

Definition at line 234 of file bsd_socket.h.

◆ EAI_SOCKTYPE

#define EAI_SOCKTYPE   10

Definition at line 235 of file bsd_socket.h.

◆ EAI_SYSTEM

#define EAI_SYSTEM   11

Definition at line 236 of file bsd_socket.h.

◆ ECONNREFUSED

#define ECONNREFUSED   111

Definition at line 254 of file bsd_socket.h.

◆ ECONNRESET

#define ECONNRESET   104

Definition at line 250 of file bsd_socket.h.

◆ EFAULT

#define EFAULT   14

Definition at line 243 of file bsd_socket.h.

◆ EINPROGRESS

#define EINPROGRESS   36

Definition at line 245 of file bsd_socket.h.

◆ EINTR

#define EINTR   4

Definition at line 240 of file bsd_socket.h.

◆ EINVAL

#define EINVAL   22

Definition at line 244 of file bsd_socket.h.

◆ EISCONN

#define EISCONN   106

Definition at line 251 of file bsd_socket.h.

◆ EMSGSIZE

#define EMSGSIZE   90

Definition at line 248 of file bsd_socket.h.

◆ ENAMETOOLONG

#define ENAMETOOLONG   63

Definition at line 247 of file bsd_socket.h.

◆ ENOPROTOOPT

#define ENOPROTOOPT   92

Definition at line 249 of file bsd_socket.h.

◆ ENOTCONN

#define ENOTCONN   107

Definition at line 252 of file bsd_socket.h.

◆ ESHUTDOWN

#define ESHUTDOWN   108

Definition at line 253 of file bsd_socket.h.

◆ ETH_P_ALL

#define ETH_P_ALL   0x0000

Definition at line 106 of file bsd_socket.h.

◆ ETH_P_ARP

#define ETH_P_ARP   0x0806

Definition at line 108 of file bsd_socket.h.

◆ ETH_P_IP

#define ETH_P_IP   0x0800

Definition at line 107 of file bsd_socket.h.

◆ ETH_P_IPV6

#define ETH_P_IPV6   0x86DD

Definition at line 109 of file bsd_socket.h.

◆ ETIMEDOUT

#define ETIMEDOUT   60

Definition at line 246 of file bsd_socket.h.

◆ EWOULDBLOCK

#define EWOULDBLOCK   11

Definition at line 242 of file bsd_socket.h.

◆ F_GETFL

#define F_GETFL   3

Definition at line 199 of file bsd_socket.h.

◆ F_SETFL

#define F_SETFL   4

Definition at line 200 of file bsd_socket.h.

◆ FD_CLR

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

Definition at line 531 of file bsd_socket.h.

◆ FD_ISSET

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

Definition at line 532 of file bsd_socket.h.

◆ FD_SET

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

Definition at line 530 of file bsd_socket.h.

◆ FD_SETSIZE

#define FD_SETSIZE   8

Definition at line 43 of file bsd_socket.h.

◆ FD_ZERO

#define FD_ZERO (   fds)    socketFdZero(fds)

Definition at line 529 of file bsd_socket.h.

◆ FIONBIO

#define FIONBIO   126

Definition at line 193 of file bsd_socket.h.

◆ FIONREAD

#define FIONREAD   127

Definition at line 194 of file bsd_socket.h.

◆ FIONSPACE

#define FIONSPACE   120

Definition at line 196 of file bsd_socket.h.

◆ FIONWRITE

#define FIONWRITE   121

Definition at line 195 of file bsd_socket.h.

◆ HOST_NOT_FOUND

#define HOST_NOT_FOUND   1

Definition at line 258 of file bsd_socket.h.

◆ INADDR_ANY

#define INADDR_ANY   0x00000000

Definition at line 115 of file bsd_socket.h.

◆ INADDR_BROADCAST

#define INADDR_BROADCAST   0xFFFFFFFF

Definition at line 117 of file bsd_socket.h.

◆ INADDR_LOOPBACK

#define INADDR_LOOPBACK   0x7F000001

Definition at line 116 of file bsd_socket.h.

◆ INADDR_NONE

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

Definition at line 264 of file bsd_socket.h.

◆ INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN   40

Definition at line 270 of file bsd_socket.h.

◆ INET_ADDRSTRLEN

#define INET_ADDRSTRLEN   16

Definition at line 267 of file bsd_socket.h.

◆ IP_ADD_MEMBERSHIP

#define IP_ADD_MEMBERSHIP   35

Definition at line 161 of file bsd_socket.h.

◆ IP_DONTFRAG

#define IP_DONTFRAG   67

Definition at line 163 of file bsd_socket.h.

◆ IP_DROP_MEMBERSHIP

#define IP_DROP_MEMBERSHIP   36

Definition at line 162 of file bsd_socket.h.

◆ IP_MULTICAST_IF

#define IP_MULTICAST_IF   32

Definition at line 158 of file bsd_socket.h.

◆ IP_MULTICAST_LOOP

#define IP_MULTICAST_LOOP   34

Definition at line 160 of file bsd_socket.h.

◆ IP_MULTICAST_TTL

#define IP_MULTICAST_TTL   33

Definition at line 159 of file bsd_socket.h.

◆ IP_PKTINFO

#define IP_PKTINFO   8

Definition at line 155 of file bsd_socket.h.

◆ IP_RECVTOS

#define IP_RECVTOS   13

Definition at line 157 of file bsd_socket.h.

◆ IP_RECVTTL

#define IP_RECVTTL   12

Definition at line 156 of file bsd_socket.h.

◆ IP_ROUTER_ALERT

#define IP_ROUTER_ALERT   5

Definition at line 154 of file bsd_socket.h.

◆ IP_TOS

#define IP_TOS   1

Definition at line 152 of file bsd_socket.h.

◆ IP_TTL

#define IP_TTL   2

Definition at line 153 of file bsd_socket.h.

◆ IPPROTO_AH

#define IPPROTO_AH   51

Definition at line 102 of file bsd_socket.h.

◆ IPPROTO_ESP

#define IPPROTO_ESP   50

Definition at line 101 of file bsd_socket.h.

◆ IPPROTO_ICMP

#define IPPROTO_ICMP   1

Definition at line 96 of file bsd_socket.h.

◆ IPPROTO_ICMPV6

#define IPPROTO_ICMPV6   58

Definition at line 103 of file bsd_socket.h.

◆ IPPROTO_IGMP

#define IPPROTO_IGMP   2

Definition at line 97 of file bsd_socket.h.

◆ IPPROTO_IP

#define IPPROTO_IP   0

Definition at line 95 of file bsd_socket.h.

◆ IPPROTO_IPV6

#define IPPROTO_IPV6   41

Definition at line 100 of file bsd_socket.h.

◆ IPPROTO_TCP

#define IPPROTO_TCP   6

Definition at line 98 of file bsd_socket.h.

◆ IPPROTO_UDP

#define IPPROTO_UDP   17

Definition at line 99 of file bsd_socket.h.

◆ IPTOS_LOWDELAY

#define IPTOS_LOWDELAY   0x10

Definition at line 188 of file bsd_socket.h.

◆ IPTOS_RELIABILITY

#define IPTOS_RELIABILITY   0x04

Definition at line 190 of file bsd_socket.h.

◆ IPTOS_THROUGHPUT

#define IPTOS_THROUGHPUT   0x08

Definition at line 189 of file bsd_socket.h.

◆ IPV6_ADD_MEMBERSHIP

#define IPV6_ADD_MEMBERSHIP   20

Definition at line 170 of file bsd_socket.h.

◆ IPV6_DONTFRAG

#define IPV6_DONTFRAG   62

Definition at line 176 of file bsd_socket.h.

◆ IPV6_DROP_MEMBERSHIP

#define IPV6_DROP_MEMBERSHIP   21

Definition at line 171 of file bsd_socket.h.

◆ IPV6_HOPLIMIT

#define IPV6_HOPLIMIT   52

Definition at line 175 of file bsd_socket.h.

◆ IPV6_MULTICAST_HOPS

#define IPV6_MULTICAST_HOPS   18

Definition at line 168 of file bsd_socket.h.

◆ IPV6_MULTICAST_IF

#define IPV6_MULTICAST_IF   17

Definition at line 167 of file bsd_socket.h.

◆ IPV6_MULTICAST_LOOP

#define IPV6_MULTICAST_LOOP   19

Definition at line 169 of file bsd_socket.h.

◆ IPV6_PKTINFO

#define IPV6_PKTINFO   50

Definition at line 173 of file bsd_socket.h.

◆ IPV6_RECVHOPLIMIT

#define IPV6_RECVHOPLIMIT   51

Definition at line 174 of file bsd_socket.h.

◆ IPV6_RECVTCLASS

#define IPV6_RECVTCLASS   66

Definition at line 177 of file bsd_socket.h.

◆ IPV6_TCLASS

#define IPV6_TCLASS   67

Definition at line 178 of file bsd_socket.h.

◆ IPV6_UNICAST_HOPS

#define IPV6_UNICAST_HOPS   16

Definition at line 166 of file bsd_socket.h.

◆ IPV6_V6ONLY

#define IPV6_V6ONLY   26

Definition at line 172 of file bsd_socket.h.

◆ MSG_CTRUNC

#define MSG_CTRUNC   0x0008

Definition at line 122 of file bsd_socket.h.

◆ MSG_DONTROUTE

#define MSG_DONTROUTE   0x0004

Definition at line 121 of file bsd_socket.h.

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   0x0040

Definition at line 123 of file bsd_socket.h.

◆ MSG_PEEK

#define MSG_PEEK   0x0002

Definition at line 120 of file bsd_socket.h.

◆ MSG_WAITALL

#define MSG_WAITALL   0x0100

Definition at line 124 of file bsd_socket.h.

◆ NETDB_SUCCESS

#define NETDB_SUCCESS   0

Definition at line 257 of file bsd_socket.h.

◆ NI_DGRAM

#define NI_DGRAM   0x10

Definition at line 219 of file bsd_socket.h.

◆ NI_NAMEREQD

#define NI_NAMEREQD   0x04

Definition at line 217 of file bsd_socket.h.

◆ NI_NOFQDN

#define NI_NOFQDN   0x01

Definition at line 215 of file bsd_socket.h.

◆ NI_NUMERICHOST

#define NI_NUMERICHOST   0x02

Definition at line 216 of file bsd_socket.h.

◆ NI_NUMERICSERV

#define NI_NUMERICSERV   0x08

Definition at line 218 of file bsd_socket.h.

◆ NO_ADDRESS

#define NO_ADDRESS   4

Definition at line 261 of file bsd_socket.h.

◆ NO_RECOVERY

#define NO_RECOVERY   3

Definition at line 260 of file bsd_socket.h.

◆ O_NONBLOCK

#define O_NONBLOCK   0x0004

Definition at line 203 of file bsd_socket.h.

◆ PF_INET

#define PF_INET   AF_INET

Definition at line 85 of file bsd_socket.h.

◆ PF_INET6

#define PF_INET6   AF_INET6

Definition at line 86 of file bsd_socket.h.

◆ PF_PACKET

#define PF_PACKET   AF_PACKET

Definition at line 87 of file bsd_socket.h.

◆ PF_UNSPEC

#define PF_UNSPEC   AF_UNSPEC

Definition at line 84 of file bsd_socket.h.

◆ SD_BOTH

#define SD_BOTH   2

Definition at line 129 of file bsd_socket.h.

◆ SD_RECEIVE

#define SD_RECEIVE   0

Definition at line 127 of file bsd_socket.h.

◆ SD_SEND

#define SD_SEND   1

Definition at line 128 of file bsd_socket.h.

◆ SHUT_RD

#define SHUT_RD   SD_RECEIVE

Definition at line 132 of file bsd_socket.h.

◆ SHUT_RDWR

#define SHUT_RDWR   SD_BOTH

Definition at line 134 of file bsd_socket.h.

◆ SHUT_WR

#define SHUT_WR   SD_SEND

Definition at line 133 of file bsd_socket.h.

◆ SO_BINDTODEVICE

#define SO_BINDTODEVICE   0x3000

Definition at line 149 of file bsd_socket.h.

◆ SO_BROADCAST

#define SO_BROADCAST   0x0020

Definition at line 140 of file bsd_socket.h.

◆ SO_DONTROUTE

#define SO_DONTROUTE   0x0010

Definition at line 139 of file bsd_socket.h.

◆ SO_ERROR

#define SO_ERROR   0x1007

Definition at line 146 of file bsd_socket.h.

◆ SO_KEEPALIVE

#define SO_KEEPALIVE   0x0008

Definition at line 138 of file bsd_socket.h.

◆ SO_LINGER

#define SO_LINGER   0x0080

Definition at line 141 of file bsd_socket.h.

◆ SO_MAX_MSG_SIZE

#define SO_MAX_MSG_SIZE   0x2003

Definition at line 148 of file bsd_socket.h.

◆ SO_RCVBUF

#define SO_RCVBUF   0x1002

Definition at line 143 of file bsd_socket.h.

◆ SO_RCVTIMEO

#define SO_RCVTIMEO   0x1006

Definition at line 145 of file bsd_socket.h.

◆ SO_REUSEADDR

#define SO_REUSEADDR   0x0004

Definition at line 137 of file bsd_socket.h.

◆ SO_SNDBUF

#define SO_SNDBUF   0x1001

Definition at line 142 of file bsd_socket.h.

◆ SO_SNDTIMEO

#define SO_SNDTIMEO   0x1005

Definition at line 144 of file bsd_socket.h.

◆ SO_TYPE

#define SO_TYPE   0x1008

Definition at line 147 of file bsd_socket.h.

◆ SOCK_DGRAM

#define SOCK_DGRAM   2

Definition at line 91 of file bsd_socket.h.

◆ SOCK_RAW

#define SOCK_RAW   3

Definition at line 92 of file bsd_socket.h.

◆ SOCK_STREAM

#define SOCK_STREAM   1

Definition at line 90 of file bsd_socket.h.

◆ SOCKET_ERROR

#define SOCKET_ERROR   (-1)

Definition at line 223 of file bsd_socket.h.

◆ SOCKET_SUCCESS

#define SOCKET_SUCCESS   0

Definition at line 222 of file bsd_socket.h.

◆ SOL_SOCKET

#define SOL_SOCKET   0xFFFF

Definition at line 112 of file bsd_socket.h.

◆ TCP_KEEPCNT

#define TCP_KEEPCNT   0x0006

Definition at line 185 of file bsd_socket.h.

◆ TCP_KEEPIDLE

#define TCP_KEEPIDLE   0x0004

Definition at line 183 of file bsd_socket.h.

◆ TCP_KEEPINTVL

#define TCP_KEEPINTVL   0x0005

Definition at line 184 of file bsd_socket.h.

◆ TCP_MAXSEG

#define TCP_MAXSEG   0x0002

Definition at line 182 of file bsd_socket.h.

◆ TCP_NODELAY

#define TCP_NODELAY   0x0001

Definition at line 181 of file bsd_socket.h.

◆ TRY_AGAIN

#define TRY_AGAIN   2

Definition at line 259 of file bsd_socket.h.

Typedef Documentation

◆ ADDRINFO

typedef struct addrinfo ADDRINFO

Information about address of a service provider.

◆ CMSGHDR

typedef struct cmsghdr CMSGHDR

Ancillary data header.

◆ fd_set

typedef struct fd_set fd_set

Set of sockets.

◆ FD_SET

typedef struct fd_set FD_SET

◆ HOSTENT

typedef struct hostent HOSTENT

Information about a given host.

◆ IN6_ADDR

typedef struct in6_addr IN6_ADDR

Structure that represents an IPv6 address.

◆ IN6_PKTINFO

typedef struct in6_pktinfo IN6_PKTINFO

IPv6 packet information.

◆ 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 289 of file bsd_socket.h.

◆ IN_PKTINFO

typedef struct in_pktinfo IN_PKTINFO

IPv4 packet information.

◆ IP_MREQ

typedef struct ip_mreq IP_MREQ

Multicast group information for IPv4 addresses.

◆ IPV6_MREQ

typedef struct ipv6_mreq IPV6_MREQ

Multicast group information for IPv6 addresses.

◆ LINGER

typedef struct linger LINGER

Linger structure.

◆ MSGHDR

typedef struct msghdr MSGHDR

Message header.

◆ PADDRINFO

typedef struct addrinfo * PADDRINFO

◆ PCMSGHDR

typedef struct cmsghdr * PCMSGHDR

◆ PFD_SET

typedef struct fd_set * PFD_SET

◆ PHOSTENT

typedef struct hostent * PHOSTENT

◆ PIN6_ADDR

typedef struct in6_addr * PIN6_ADDR

◆ PIN6_PKTINFO

typedef struct in6_pktinfo * PIN6_PKTINFO

◆ PIN_ADDR

typedef struct in_addr * PIN_ADDR

◆ PIN_PKTINFO

typedef struct in_pktinfo * PIN_PKTINFO

◆ PIP_MREQ

typedef struct ip_mreq * PIP_MREQ

◆ PIPV6_MREQ

typedef struct ipv6_mreq * PIPV6_MREQ

◆ PLINGER

typedef struct linger * PLINGER

◆ PMSGHDR

typedef struct msghdr * PMSGHDR

◆ PSOCKADDR

typedef struct sockaddr * PSOCKADDR

◆ PSOCKADDR_IN

typedef struct sockaddr_in * PSOCKADDR_IN

◆ PSOCKADDR_IN6

typedef struct sockaddr_in6 * PSOCKADDR_IN6

◆ PSOCKADDR_STORAGE

◆ PTIMEVAL

typedef struct timeval * PTIMEVAL

◆ 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.

◆ SOCKADDR_STORAGE

Socket address storage.

◆ socklen_t

typedef int_t socklen_t

Length type.

Definition at line 282 of file bsd_socket.h.

◆ TIMEVAL

typedef struct timeval TIMEVAL

Timeout structure.

Function Documentation

◆ accept()

int_t accept ( int_t  s,
struct 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 360 of file bsd_socket.c.

◆ bind()

int_t bind ( int_t  s,
const struct 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 107 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 2381 of file bsd_socket.c.

◆ connect()

int_t connect ( int_t  s,
const struct 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 204 of file bsd_socket.c.

◆ fcntl()

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

Perform specific operation.

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

Definition at line 2287 of file bsd_socket.c.

◆ freeaddrinfo()

void freeaddrinfo ( struct addrinfo res)

Free socket address structures.

Parameters
[in]resDynamically allocated list of socket address structures

Definition at line 2983 of file bsd_socket.c.

◆ getaddrinfo()

int_t getaddrinfo ( const char_t node,
const char_t service,
const struct addrinfo hints,
struct addrinfo **  res 
)

Convert host and service names to socket address.

Parameters
[in]nodeHost name or numerical network address
[in]serviceService name or decimal number
[in]hintsCriteria for selecting the socket address structures
[out]resDynamically allocated list of socket address structures
Returns
On success, zero is returned. On error, a non-zero value is returned

Definition at line 2743 of file bsd_socket.c.

◆ gethostbyname()

struct hostent* gethostbyname ( const char_t name)

Host name resolution.

Parameters
[in]nameName of the host to resolve
Returns
Pointer to the hostent structure or a NULL if an error occurs

Definition at line 2646 of file bsd_socket.c.

◆ gethostbyname_r()

struct hostent* gethostbyname_r ( const char_t name,
struct hostent result,
char_t buf,
size_t  buflen,
int_t h_errnop 
)

Host name resolution (reentrant version)

Parameters
[in]nameName of the host to resolve
[in]resultPointer to a hostent structure where the function can store the host entry
[out]bufPointer to a temporary work buffer
[in]buflenLength of the temporary work buffer
[out]h_errnopPointer to a location where the function can store an h_errno value if an error occurs
Returns
Pointer to the hostent structure or a NULL if an error occurs

Definition at line 2669 of file bsd_socket.c.

◆ gethostname()

int_t gethostname ( char_t name,
size_t  len 
)

Get system host name.

Parameters
[out]nameOutput buffer where to store the system host name
[in]lenLength of the buffer, in bytes
Returns
On success, zero is returned. On error, -1 is returned

Definition at line 2605 of file bsd_socket.c.

◆ getnameinfo()

int_t getnameinfo ( const struct sockaddr addr,
socklen_t  addrlen,
char_t host,
size_t  hostlen,
char_t serv,
size_t  servlen,
int  flags 
)

Convert a socket address to a corresponding host and service.

Parameters
[in]addrGeneric socket address structure
[in]addrlenLength in bytes of the address
[out]hostOutput buffer where to store the host name
[in]hostlenLength of the host name buffer, in bytes
[out]servOutput buffer where to store the service name
[in]servlenLength of the service name buffer, in bytes
[in]flagsSet of flags that influences the behavior of this function
Returns
On success, zero is returned. On error, a non-zero value is returned

Definition at line 3012 of file bsd_socket.c.

◆ getpeername()

int_t getpeername ( int_t  s,
struct 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 1572 of file bsd_socket.c.

◆ getsockname()

int_t getsockname ( int_t  s,
struct 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 1476 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 1939 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 3108 of file bsd_socket.c.

◆ inet_aton()

int_t inet_aton ( const char_t cp,
struct 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 3142 of file bsd_socket.c.

◆ inet_ntoa()

const char_t* inet_ntoa ( struct in_addr  in)

Convert a binary IPv4 address to dot-decimal notation.

Parameters
[in]inBinary representation of the IPv4 address
Returns
Pointer to the formatted string

Definition at line 3177 of file bsd_socket.c.

◆ inet_ntoa_r()

const char_t* inet_ntoa_r ( struct in_addr  in,
char_t buf,
socklen_t  buflen 
)

Convert a binary IPv4 address to dot-decimal notation (reentrant version)

Parameters
[in]inBinary representation of the IPv4 address
[out]bufPointer to the buffer where to format the string
[in]buflenNumber of bytes available in the buffer
Returns
Pointer to the formatted string

Definition at line 3194 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 3294 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 3222 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 2187 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 322 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 917 of file bsd_socket.c.

◆ recvfrom()

int_t recvfrom ( int_t  s,
void *  data,
size_t  size,
int_t  flags,
struct 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. Otherwise, a value of SOCKET_ERROR is returned

Definition at line 989 of file bsd_socket.c.

◆ recvmsg()

int_t recvmsg ( int_t  s,
struct msghdr msg,
int_t  flags 
)

Receive a message.

Parameters
[in]sDescriptor that identifies a socket
[in,out]msgPointer to the structure describing the message
[in]flagsSet of flags that influences the behavior of this function
Returns
If no error occurs, recvmsg returns the number of bytes received. Otherwise, a value of SOCKET_ERROR is returned

Definition at line 1115 of file bsd_socket.c.

◆ select()

int_t select ( int_t  nfds,
fd_set readfds,
fd_set writefds,
fd_set exceptfds,
const struct 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 2423 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 459 of file bsd_socket.c.

◆ sendmsg()

int_t sendmsg ( int_t  s,
struct msghdr msg,
int_t  flags 
)

Send a message.

Parameters
[in]sDescriptor that identifies a socket
[in]msgPointer to the structure describing the message
[in]flagsSet of flags that influences the behavior of this function
Returns
If no error occurs, sendmsg 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 661 of file bsd_socket.c.

◆ sendto()

int_t sendto ( int_t  s,
const void *  data,
size_t  length,
int_t  flags,
const struct 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 535 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 1672 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 2345 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 65 of file bsd_socket.c.

◆ socketCmsgFirstHdr()

struct cmsghdr* socketCmsgFirstHdr ( struct msghdr msg)

Get first ancillary data header.

Parameters
[in]msgPointer to the message header
Returns
Pointer to the first ancillary data header

Definition at line 50 of file bsd_socket_misc.c.

◆ socketCmsgNextHdr()

struct cmsghdr* socketCmsgNextHdr ( struct msghdr msg,
struct cmsghdr cmsg 
)

Get next ancillary data header.

Parameters
[in]msgPointer to the message header
[in]cmsgPointer to the current ancillary data header
Returns
Pointer to the next ancillary data header

Definition at line 80 of file bsd_socket_misc.c.

◆ socketFdClr()

void socketFdClr ( 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 160 of file bsd_socket_misc.c.

◆ socketFdIsSet()

int_t socketFdIsSet ( 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 194 of file bsd_socket_misc.c.

◆ socketFdSet()

void socketFdSet ( 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 131 of file bsd_socket_misc.c.

◆ socketFdZero()

void socketFdZero ( fd_set fds)

Initializes a descriptor set.

Parameters
[in]fdsPointer to a descriptor set

Definition at line 118 of file bsd_socket_misc.c.

Variable Documentation

◆ in6addr_any

const struct in6_addr in6addr_any
extern

Definition at line 1 of file bsd_socket.c.

◆ in6addr_loopback

const struct in6_addr in6addr_loopback
extern

Definition at line 1 of file bsd_socket.c.