Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

bsd_socket.h File Reference

bsd_socket.h File Reference

BSD socket API. More...

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

Typedefs

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

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

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

Definition in file bsd_socket.h.


Typedef Documentation

typedef struct fd_set fd_set

Set of sockets.

typedef struct hostent hostent

Information about a given host.

typedef struct in6_addr in6_addr

Structure that represents an IPv6 address.

typedef struct in_addr in_addr

Structure that represents an IPv4 address.

typedef uint32_t in_addr_t

IPv4 address.

Definition at line 172 of file bsd_socket.h.

typedef struct sockaddr sockaddr

Socket address.

typedef struct sockaddr_in sockaddr_in

IPv4 address information.

typedef struct sockaddr_in6 sockaddr_in6

IPv6 address information.

typedef int_t socklen_t

Length type.

Definition at line 165 of file bsd_socket.h.

typedef struct timeval timeval

Timeout structure.


Function Documentation

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.

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.

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 1490 of file bsd_socket.c.

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.

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 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]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 1797 of file bsd_socket.c.

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.

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.

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.

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

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.

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.

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 1528 of file bsd_socket.c.

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 1740 of file bsd_socket.c.

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 1772 of file bsd_socket.c.

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 1711 of file bsd_socket.c.

void selectFdZero ( fd_set fds )

Initializes a descriptor set.

Parameters:
[in]fdsPointer 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]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.

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.

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.

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