m2mb API docs  25.21.003
m2mb API sets documentation
m2mb_socket.h File Reference

Socket support. More...

Go to the source code of this file.

Data Structures

struct  M2MB_SOCKET_BSD_LINGER
 
struct  M2MB_SOCKET_BSD_SOCKADDR
 
struct  M2MB_SOCKET_BSD_IN_ADDR
 
struct  M2MB_SOCKET_BSD_SOCKADDR_IN
 
struct  M2MB_SOCKET_BSD_IN6_ADDR
 
struct  M2MB_SOCKET_BSD_IPV6_ADDR
 
struct  M2MB_SOCKET_BSD_SOCKADDR_IN6
 
struct  M2MB_SOCKET_BSD_HOSTENT
 
struct  M2MB_SOCKET_BSD_TIMEVAL
 
struct  M2MB_SOCKET_BSD_FD_SET
 

Macros

#define M2MB_SOCKET_BSD_INVALID_SOCKET   (M2MB_SOCKET_BSD_SOCKET)(~0) /* Invalid socket handle */
 
#define M2MB_SOCKET_BSD_SOCK_STREAM   1 /* Stream socket type used for TCP */
 
#define M2MB_SOCKET_BSD_SOCK_DGRAM   2 /* Datagram socket type used for UDP */
 
#define M2MB_SOCKET_BSD_SOCK_RAW   3 /* Raw socket type */
 
#define M2MB_SOCKET_BSD_AF_UNSPEC   0 /* Unspecified Address Family */
 
#define M2MB_SOCKET_BSD_AF_INET   2 /* Internetwork: UDP, TCP, etc. */
 
#define M2MB_SOCKET_BSD_AF_INET6   10
 
#define M2MB_SOCKET_BSD_PF_UNSPEC   0 /* Unspecified Protocol Family */
 
#define M2MB_SOCKET_BSD_PF_INET   2 /* Internetwork: UDP, TCP, etc. */
 
#define M2MB_SOCKET_BSD_IPPROTO_IP   0 /* Dummy for IP */
 
#define M2MB_SOCKET_BSD_IPPROTO_TCP   6 /* Transmission Control Protocol */
 
#define M2MB_SOCKET_BSD_IPPROTO_UDP   17 /* User Datagram Protocol */
 
#define M2MB_SOCKET_BSD_IPPROTO_ICMP   1 /* Internet Control Message Protocol */
 
#define M2MB_SOCKET_BSD_SOL_SOCKET   0xffff /* options for socket level */
 
#define M2MB_SOCKET_BSD_SO_DEBUG   0x0001 /* Turn on debugging info recording */
 
#define M2MB_SOCKET_BSD_SO_ACCEPTCONN   0x0002 /* Socket has had listen() */
 
#define M2MB_SOCKET_BSD_SO_REUSEADDR   0x0004 /* Allow local address reuse */
 
#define M2MB_SOCKET_BSD_SO_KEEPALIVE   0x0008 /* Keep connections alive, not enabled by default */
 
#define M2MB_SOCKET_BSD_SO_DONTROUTE   0x0010 /* Just use interface addresses */
 
#define M2MB_SOCKET_BSD_SO_BROADCAST   0x0020 /* Permit sending of broadcast msgs */
 
#define M2MB_SOCKET_BSD_SO_LINGER   0x0080 /* Linger on close if data present */
 
#define M2MB_SOCKET_BSD_SO_OOBINLINE   0x0100 /* Leave received OOB data in line */
 
#define M2MB_SOCKET_BSD_SO_DONTLINGER   (INT32)(~M2MB_SOCKET_BSD_SO_LINGER) /* Dont Linger */
 
#define M2MB_SOCKET_BSD_SO_SNDBUF   0x1001 /* Send buffer size */
 
#define M2MB_SOCKET_BSD_SO_RCVBUF   0x1002 /* Receive buffer size */
 
#define M2MB_SOCKET_BSD_SO_SNDLOWAT   0x1003 /* Send low-water mark */
 
#define M2MB_SOCKET_BSD_SO_RCVLOWAT   0x1004 /* Receive low-water mark */
 
#define M2MB_SOCKET_BSD_SO_SNDTIMEO   0x1005 /* Send timeout */
 
#define M2MB_SOCKET_BSD_SO_RCVTIMEO   0x1006 /* Receive timeout */
 
#define M2MB_SOCKET_BSD_SO_ERROR   0x1007 /* Get error status and clear */
 
#define M2MB_SOCKET_BSD_SO_TYPE   0x1008 /* Get socket type */
 
#define M2MB_SOCKET_BSD_SO_TXDATA   0x1009 /* Get a count of bytes in send buffer */
 
#define M2MB_SOCKET_BSD_SO_RXDATA   0x1010 /* Get a count of bytes in receive buffer */
 
#define M2MB_SOCKET_BSD_TCP_NODELAY   0x01 /* Don't delay send to coalesce packets */
 
#define M2MB_SOCKET_BSD_TCP_KEEPALIVE   0x03 /* TCP keepalive timer */
 
#define M2MB_SOCKET_BSD_INADDR_ANY   (UINT32) 0x00000000
 
#define M2MB_SOCKET_BSD_INADDR_LOOPBACK   (UINT32) 0x7f000001
 
#define M2MB_SOCKET_BSD_INADDR_BROADCAST   (UINT32) 0xffffffff
 
#define M2MB_SOCKET_BSD_SHUT_RD   0x00 /* Read socket */
 
#define M2MB_SOCKET_BSD_SHUT_WR   0x01 /* Write socket */
 
#define M2MB_SOCKET_BSD_SHUT_RDWR   0x02 /* Read Write socket */
 
#define M2MB_SOCKET_BSD_FIONREAD   0
 
#define M2MB_SOCKET_BSD_FIONBIO   1
 
#define M2MB_SOCKET_BSD_SOCKET_ERROR   (-1)
 
#define M2MB_SOCKET_BSD_SOCKNOERROR   0
 
#define M2MB_SOCKET_BSD_EUNDEFINED   1
 
#define M2MB_SOCKET_BSD_EACCES   2
 
#define M2MB_SOCKET_BSD_EADDRINUSE   3
 
#define M2MB_SOCKET_BSD_EADDRNOTAVAIL   4
 
#define M2MB_SOCKET_BSD_EAFNOSUPPORT   5
 
#define M2MB_SOCKET_BSD_EALREADY   6
 
#define M2MB_SOCKET_BSD_EBADF   7
 
#define M2MB_SOCKET_BSD_ECONNABORTED   8
 
#define M2MB_SOCKET_BSD_ECONNREFUSED   9
 
#define M2MB_SOCKET_BSD_ECONNRESET   10
 
#define M2MB_SOCKET_BSD_EDESTADDRREQ   11
 
#define M2MB_SOCKET_BSD_EFAULT   12
 
#define M2MB_SOCKET_BSD_EHOSTDOWN   13
 
#define M2MB_SOCKET_BSD_EHOSTUNREACH   14
 
#define M2MB_SOCKET_BSD_EINPROGRESS   15
 
#define M2MB_SOCKET_BSD_EINTR   16
 
#define M2MB_SOCKET_BSD_EINVAL   17
 
#define M2MB_SOCKET_BSD_EISCONN   18
 
#define M2MB_SOCKET_BSD_EMFILE   19
 
#define M2MB_SOCKET_BSD_EMSGSIZE   20
 
#define M2MB_SOCKET_BSD_ENETDOWN   21
 
#define M2MB_SOCKET_BSD_ENETRESET   22
 
#define M2MB_SOCKET_BSD_ENETUNREACH   23
 
#define M2MB_SOCKET_BSD_ENOBUFS   24
 
#define M2MB_SOCKET_BSD_ENOPROTOOPT   25
 
#define M2MB_SOCKET_BSD_ENOTCONN   26
 
#define M2MB_SOCKET_BSD_ENOTSOCK   27
 
#define M2MB_SOCKET_BSD_EOPNOTSUPP   28
 
#define M2MB_SOCKET_BSD_EPFNOSUPPORT   29
 
#define M2MB_SOCKET_BSD_EPROTONOSUPPORT   30
 
#define M2MB_SOCKET_BSD_EPROTOTYPE   31
 
#define M2MB_SOCKET_BSD_ESHUTDOWN   32
 
#define M2MB_SOCKET_BSD_ESOCKTNOSUPPORT   33
 
#define M2MB_SOCKET_BSD_ETIMEDOUT   34
 
#define M2MB_SOCKET_BSD_EWOULDBLOCK   35
 
#define M2MB_SOCKET_HOST_NOT_FOUND   210
 
#define M2MB_SOCKET_NO_DATA   211
 
#define M2MB_SOCKET_NO_RECOVERY   212
 
#define M2MB_SOCKET_TRY_AGAIN   213
 
#define M2MB_SOCKET_ERANGE   214
 
#define addr8_s   v6_v.addr8
 
#define addr16_s   v6_v.addr16
 
#define addr32_s   v6_v.addr32
 
#define M2MB_SOCKET_BSD_FD_SETSIZE   32
 

Typedefs

typedef iHANDLE M2MB_SOCKET_BSD_SOCKET
 
typedef struct M2MB_SOCKET_BSD_FD_SET M2MB_SOCKET_BSD_FD_SET_T
 

Functions

M2MB_SOCKET_BSD_SOCKET m2mb_socket_bsd_socket (INT32 domain, INT32 type, INT32 protocol)
 create an endpoint for communication More...
 
INT32 m2mb_socket_bsd_bind (M2MB_SOCKET_BSD_SOCKET s, struct M2MB_SOCKET_BSD_SOCKADDR *name, INT32 namelen)
 bind the address with the socket More...
 
INT32 m2mb_socket_bsd_connect (M2MB_SOCKET_BSD_SOCKET s, const struct M2MB_SOCKET_BSD_SOCKADDR *name, INT32 namelen)
 connect a socket More...
 
INT32 m2mb_socket_bsd_listen (M2MB_SOCKET_BSD_SOCKET s, INT32 backlog)
 listen for connections on a socket More...
 
M2MB_SOCKET_BSD_SOCKET m2mb_socket_bsd_accept (M2MB_SOCKET_BSD_SOCKET s, struct M2MB_SOCKET_BSD_SOCKADDR *name, INT32 *namelen)
 accept a connection on a socket More...
 
INT32 m2mb_socket_bsd_close (M2MB_SOCKET_BSD_SOCKET s)
 close a socket More...
 
INT32 m2mb_socket_bsd_get_peer_name (M2MB_SOCKET_BSD_SOCKET s, struct M2MB_SOCKET_BSD_SOCKADDR *name, INT32 *namelen)
 get the name of the peer socket More...
 
INT32 m2mb_socket_bsd_get_sock_name (M2MB_SOCKET_BSD_SOCKET s, struct M2MB_SOCKET_BSD_SOCKADDR *name, INT32 *namelen)
 get socket name More...
 
INT32 m2mb_socket_bsd_recv (M2MB_SOCKET_BSD_SOCKET s, void *buf, INT32 len, INT32 flags)
 receive a message from a socket More...
 
INT32 m2mb_socket_bsd_recv_from (M2MB_SOCKET_BSD_SOCKET s, void *buf, INT32 len, INT32 flags, struct M2MB_SOCKET_BSD_SOCKADDR *from, INT32 *fromlen)
 receive a message from a socket More...
 
INT32 m2mb_socket_bsd_send (M2MB_SOCKET_BSD_SOCKET s, const void *buf, INT32 len, INT32 flags)
 send a message on a socket More...
 
INT32 m2mb_socket_bsd_send_to (M2MB_SOCKET_BSD_SOCKET s, const void *buf, INT32 len, INT32 flags, const struct M2MB_SOCKET_BSD_SOCKADDR *to, INT32 tolen)
 send a message on a socket More...
 
INT32 m2mb_socket_bsd_get_sock_opt (M2MB_SOCKET_BSD_SOCKET s, INT32 level, INT32 optname, void *optval, INT32 *optlen)
 get options from sockets More...
 
INT32 m2mb_socket_bsd_set_sock_opt (M2MB_SOCKET_BSD_SOCKET s, INT32 level, INT32 optname, const void *optval, INT32 optlen)
 set options on sockets More...
 
INT32 m2mb_socket_bsd_ioctl (M2MB_SOCKET_BSD_SOCKET s, INT32 cmd, void *argp)
 IO control function. More...
 
INT32 m2mb_socket_bsd_select (INT32 nfds, M2MB_SOCKET_BSD_FD_SET_T *readfds, M2MB_SOCKET_BSD_FD_SET_T *writefds, M2MB_SOCKET_BSD_FD_SET_T *exceptfds, const struct M2MB_SOCKET_BSD_TIMEVAL *timeout)
 synchronous I/O multiplexing More...
 
void m2mb_socket_bsd_fd_zero_func (M2MB_SOCKET_BSD_FD_SET_T *set)
 used for m2mb_socket_bsd_select() More...
 
void m2mb_socket_bsd_fd_set_func (INT32 fd, M2MB_SOCKET_BSD_FD_SET_T *set)
 used for m2mb_socket_bsd_select() More...
 
void m2mb_socket_bsd_fd_clr_func (INT32 fd, M2MB_SOCKET_BSD_FD_SET_T *set)
 used for m2mb_socket_bsd_select() More...
 
UINT8 m2mb_socket_bsd_fd_isset_func (INT32 fd, M2MB_SOCKET_BSD_FD_SET_T *set)
 used for m2mb_socket_bsd_select() More...
 
INT32 m2mb_socket_errno (void)
 Gets the last error occured. More...
 
UINT16 m2mb_socket_bsd_htons (UINT16 x)
 convertion between host and network byte order More...
 
UINT16 m2mb_socket_bsd_ntohs (UINT16 x)
 convertion between host and network byte order More...
 
UINT32 m2mb_socket_bsd_htonl (UINT32 x)
 convertion between host and network byte order More...
 
UINT32 m2mb_socket_bsd_ntohl (UINT32 x)
 convertion between host and network byte order More...
 
CHAR * m2mb_socket_bsd_inet_ntop (INT32 af, const void *src, CHAR *dst, SIZE_T size)
 convert IPv4 and IPv6 addresses from binary to text form More...
 
INT32 m2mb_socket_bsd_inet_pton (INT32 af, const CHAR *src, void *dst)
 convert IPv4 and IPv6 addresses from text to binary form More...
 
INT32 m2mb_socket_bsd_get_host_by_name_2_r_cid (const CHAR *name, INT32 af, struct M2MB_SOCKET_BSD_HOSTENT *ret, CHAR *buf, SIZE_T buflen, struct M2MB_SOCKET_BSD_HOSTENT **result, INT32 *h_errnop, UINT8 cid)
 get network host entry More...
 
INT32 m2mb_socket_set_cid (M2MB_SOCKET_BSD_SOCKET s, UINT8 cid)
 link a socket to a cid More...
 

Detailed Description

Socket support.

m2m/m2m_generic/common/m2mb_inc/m2mb_socket.h

socket APIs from BSD and Linux

@notes Dependencies: #include <m2mb_types.h> #include <m2mb_socket.h> #include <m2mb_trace.h>

Author
M.Francesca Tammaro
Date
20/02/2017

Function Documentation

◆ m2mb_socket_bsd_accept()

M2MB_SOCKET_BSD_SOCKET m2mb_socket_bsd_accept ( M2MB_SOCKET_BSD_SOCKET  s,
struct M2MB_SOCKET_BSD_SOCKADDR name,
INT32 *  namelen 
)

accept a connection on a socket

allows an incoming connection attempt on the specified socket. Accept is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection

Parameters
[in]sspecifies the file descriptor of the socket
[in]nameit is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket
[in]namelenit is a value-result argument: the caller must initialize it to contain the size (in bytes) of the structure pointed to by name; on return it will contain the actual size of the peer address
Returns
On success, a handle for the new socket is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_bind()

INT32 m2mb_socket_bsd_bind ( M2MB_SOCKET_BSD_SOCKET  s,
struct M2MB_SOCKET_BSD_SOCKADDR name,
INT32  namelen 
)

bind the address with the socket

bind is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address

Parameters
[in]sspecifies the file descriptor of the socket to be bound
[in]namepoints to a sockaddr structure containing the address to be bound to the socket. The length and format of the address depend on the address family of the socket: M2MB_SOCKET_BSD_SOCKADDR_IN is used for IPv4 Internet protocols M2MB_SOCKET_BSD_SOCKADDR_IN6 is used for IPv6 Internet protocols
[in]namelenspecifies the length of the sockaddr structure pointed to by name
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_close()

INT32 m2mb_socket_bsd_close ( M2MB_SOCKET_BSD_SOCKET  s)

close a socket

closes a file descriptor, so that it no longer refers to any file and may be reused

Parameters
[in]sspecifies the file descriptor of the socket
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_connect()

INT32 m2mb_socket_bsd_connect ( M2MB_SOCKET_BSD_SOCKET  s,
const struct M2MB_SOCKET_BSD_SOCKADDR name,
INT32  namelen 
)

connect a socket

Establishes a connection to the specified address

Parameters
[in]sspecifies the file descriptor of the socket
[in]namepoints to a sockaddr structure containing the peer address. The length and format of the address depend on the address family of the socket: M2MB_SOCKET_BSD_SOCKADDR_IN is used for IPv4 Internet protocols M2MB_SOCKET_BSD_SOCKADDR_IN6 is used for IPv6 Internet protocols
[in]namelenspecifies the length of the sockaddr structure pointed to by name
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_fd_clr_func()

void m2mb_socket_bsd_fd_clr_func ( INT32  fd,
M2MB_SOCKET_BSD_FD_SET_T set 
)

used for m2mb_socket_bsd_select()

remove a file descriptor from a set

Parameters
[in]fdfile descriptor
[in]setset of file descriptors
Returns
<Return value="" description>="">
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_fd_isset_func()

UINT8 m2mb_socket_bsd_fd_isset_func ( INT32  fd,
M2MB_SOCKET_BSD_FD_SET_T set 
)

used for m2mb_socket_bsd_select()

tests to see if a file descriptor is part of a set

Parameters
[in]fdfile descriptor
[in]setset of file descriptors
Returns
On success, 0 is returned if the socket is not a member; 1 is returned if the socket is a member. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_fd_set_func()

void m2mb_socket_bsd_fd_set_func ( INT32  fd,
M2MB_SOCKET_BSD_FD_SET_T set 
)

used for m2mb_socket_bsd_select()

add a file descriptor to a set

Parameters
[in]fdfile descriptor
[in]setset of file descriptors
Returns
<Return value="" description>="">
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_fd_zero_func()

void m2mb_socket_bsd_fd_zero_func ( M2MB_SOCKET_BSD_FD_SET_T set)

used for m2mb_socket_bsd_select()

clears a set of file descriptors

Parameters
[in]setset of file descriptors
Returns
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_get_host_by_name_2_r_cid()

INT32 m2mb_socket_bsd_get_host_by_name_2_r_cid ( const CHAR *  name,
INT32  af,
struct M2MB_SOCKET_BSD_HOSTENT ret,
CHAR *  buf,
SIZE_T  buflen,
struct M2MB_SOCKET_BSD_HOSTENT **  result,
INT32 *  h_errnop,
UINT8  cid 
)

get network host entry

implements a "standard" Unix version of gethostbyname2_r() but with parameter "cid" to specify the PDP context to be used for transferring data

Parameters
[in]nameeither a hostname, or an IPv4 address in standard dot notation or an IPv6 address in colon notation
[in]afaddress family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6
[in]retpre-allocated struct where to store the result
[in]bufpre-allocated buffer where to store additional data
[in]buflenthe size of buf
[in]resultpointer to a hostent pointer that is set to ret on success and set to zero on error
[in]h_errnoppointer to an int where to store errors (instead of modifying the global h_errno)
[in]cidPDP context to be used
Returns
0 on success, non-zero on error, additional error information is stored in *h_errnop instead of h_errno
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_get_peer_name()

INT32 m2mb_socket_bsd_get_peer_name ( M2MB_SOCKET_BSD_SOCKET  s,
struct M2MB_SOCKET_BSD_SOCKADDR name,
INT32 *  namelen 
)

get the name of the peer socket

retrieves the peer address of the specified socket, store this address in the sockaddr structure pointed to by name, and store the length of this address in the object pointed to by namelen

Parameters
[in]sspecifies the file descriptor of the socket
[in]nameis a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket
[in]namelenit is a value-result argument: the caller must initialize it to contain the size (in bytes) of the structure pointed to by name; on return it will contain the actual size of the peer address
Returns
On success, 0 is returned On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_get_sock_name()

INT32 m2mb_socket_bsd_get_sock_name ( M2MB_SOCKET_BSD_SOCKET  s,
struct M2MB_SOCKET_BSD_SOCKADDR name,
INT32 *  namelen 
)

get socket name

retrieve the local address of the specified socket, store this address in the sockaddr structure pointed to by name, and store the length of this address in the object pointed to by namelen

Parameters
[in]sspecifies the file descriptor of the socket
[in]nameis a pointer to a sockaddr structure. This structure is filled in with the local address of the socket
[in]namelenit is a value-result argument: the caller must initialize it to contain the size (in bytes) of the structure pointed to by name; on return it will contain the actual size of the peer address
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_get_sock_opt()

INT32 m2mb_socket_bsd_get_sock_opt ( M2MB_SOCKET_BSD_SOCKET  s,
INT32  level,
INT32  optname,
void *  optval,
INT32 *  optlen 
)

get options from sockets

This function is used to retrieve the current value of a particular socket option for the specified socket, see m2mb_socket_option_flags socket options

Parameters
[in]sspecifies the file descriptor of the socket
[in]levelprotocol level the option exists at
[in]optnamename of the option
[in]optvalpointer to a buffer in which the value for the requested option is to be returned
[in]optlenoption length in bytes
Returns
On success, is returned0. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_htonl()

UINT32 m2mb_socket_bsd_htonl ( UINT32  x)

convertion between host and network byte order

converts the unsigned integer x from host byte order to network byte order.

Parameters
[in]xunsigned integer to be converted
Returns
result of the conversion
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_htons()

UINT16 m2mb_socket_bsd_htons ( UINT16  x)

convertion between host and network byte order

converts the unsigned short integer x from host byte order to network byte order

Parameters
[in]xunsigned short integer to be converted
Returns
result of the conversion
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_inet_ntop()

CHAR* m2mb_socket_bsd_inet_ntop ( INT32  af,
const void *  src,
CHAR *  dst,
SIZE_T  size 
)

convert IPv4 and IPv6 addresses from binary to text form

this function converts the network address structure src in the af address family into a character string. The resulting string is copied to the buffer pointed to by dst, which must be a non-NULL pointer. The caller specifies the number of bytes available in this buffer in the argument size

Parameters
[in]afAddress family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6
[in]srcPointer to IPv4 or IPv6 address
[in]dstPointer to output buffer to contain IPv4/IPv6 address string
[in]sizeSize of output buffer in bytes
Returns
on success, returns a non-NULL pointer to dst. NULL is returned if there was an error
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_inet_pton()

INT32 m2mb_socket_bsd_inet_pton ( INT32  af,
const CHAR *  src,
void *  dst 
)

convert IPv4 and IPv6 addresses from text to binary form

converts the character string src into a network address structure in the af address family, then copies the network address structure to dst

Parameters
[in]afAddress family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6
[in]srcIPv4 or IPv6 address string (null-terminated)
[in]dstResulting IPv4/IPv6 address: struct M2MB_SOCKET_BSD_IN_ADDR in case of IPv4, struct M2MB_SOCKET_BSD_IPV6_ADDR in case of IPv6
Returns
returns 1 on success (network address was successfully converted). 0 is returned if src does not contain a character string representing a valid network address in the specified address family. If af does not contain a valid address family, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_ioctl()

INT32 m2mb_socket_bsd_ioctl ( M2MB_SOCKET_BSD_SOCKET  s,
INT32  cmd,
void *  argp 
)

IO control function.

used to set a socket to blocking or nonblocking mode (M2MB_SOCKET_BSD_FIONBIO) or to retrieve all pending data (M2MB_SOCKET_BSD_FIONREAD)

Parameters
[in]cmdname of the command: M2MB_SOCKET_BSD_FIONREAD,M2MB_SOCKET_BSD_FIONBIO
[in]argppointer to the value (input parameter or output parameter)
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_listen()

INT32 m2mb_socket_bsd_listen ( M2MB_SOCKET_BSD_SOCKET  s,
INT32  backlog 
)

listen for connections on a socket

marks the socket referred to by sockfd as a passive socket, that is, as a socket that will be used to accept incoming connection requests using m2mb_socket_bsd_accept

Parameters
[in]sspecifies the file descriptor of the socket
[in]backlogdefines the maximum length to which the queue of pending connections for s may grow
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_ntohl()

UINT32 m2mb_socket_bsd_ntohl ( UINT32  x)

convertion between host and network byte order

converts the unsigned integer x from network byte order to host byte order.

Parameters
[in]xunsigned integer to be converted
Returns
result of the conversion
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_ntohs()

UINT16 m2mb_socket_bsd_ntohs ( UINT16  x)

convertion between host and network byte order

onverts the unsigned short integer x from network byte order to host byte order

Parameters
[in]xunsigned short integer to be converted
Returns
result of the conversion
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_recv()

INT32 m2mb_socket_bsd_recv ( M2MB_SOCKET_BSD_SOCKET  s,
void *  buf,
INT32  len,
INT32  flags 
)

receive a message from a socket

This function should be invoked to receive the data on the specified socket. Depending on the socket configuration, this function can perform in a blocking or non-blocking mode. In case of blocking, this function will not return until data is received (not neccessarily all requested data). In case of non-blocking, this function will return the data pending on the specified socket, but will not wait for additional data (in case the size requested is not reached)

Parameters
[in]sspecifies the file descriptor of the socket
[in]bufPointer to a buffer for received message
[in]lenNumber of bytes to receive
[in]flagsonly 0 supported
Returns
number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_recv_from()

INT32 m2mb_socket_bsd_recv_from ( M2MB_SOCKET_BSD_SOCKET  s,
void *  buf,
INT32  len,
INT32  flags,
struct M2MB_SOCKET_BSD_SOCKADDR from,
INT32 *  fromlen 
)

receive a message from a socket

This function receives the data on the given socket and stores the source address. This function shall be used only for datagram sockets. Depending on the socket configuration, this function can perform in a blocking or non-blocking mode. In case of blocking, this function will not return until data is received (not neccessarily all requested data). In case of non-blocking, this function will return the data pending on the specified socket, but will not wait for additional data (in case the size requested is not reached)

Parameters
[in]sspecifies the file descriptor of the socket
[in]bufPointer to a buffer for received message
[in]lenNumber of bytes to receive
[in]flagsonly 0 supported
[in]fromis a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket
[in]fromlenit is a value-result argument: the caller must initialize it to contain the size (in bytes) of the structure pointed to by addr; on return it will contain the actual size of the peer address
Returns
number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_select()

INT32 m2mb_socket_bsd_select ( INT32  nfds,
M2MB_SOCKET_BSD_FD_SET_T readfds,
M2MB_SOCKET_BSD_FD_SET_T writefds,
M2MB_SOCKET_BSD_FD_SET_T exceptfds,
const struct M2MB_SOCKET_BSD_TIMEVAL timeout 
)

synchronous I/O multiplexing

This function is used to prune a provided list of sockets for those that are: ready to read, ready to write or have errors

Parameters
[in]nfdsnfds is the highest-numbered file descriptor in any of the three sets, plus 1
[in]readfdsset of file descriptors that will be watched to see if characters become available for reading. On exit, the set is modified in place to indicate which file descriptors actually changed status.
[in]writefdsset of file descriptors that will be watched to see if a write will not block. On exit, the set is modified in place to indicate which file descriptors actually changed status.
[in]exceptfdsset of file descriptors that will be watched for exceptions. On exit, the set is modified in place to indicate which file descriptors actually changed status.
[in]timeoutspecifies the minimum interval that m2mb_socket_bsd_select() should block waiting for a file descriptor to become ready
Returns
number of sockets which had an event occur at and become ready
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_send()

INT32 m2mb_socket_bsd_send ( M2MB_SOCKET_BSD_SOCKET  s,
const void *  buf,
INT32  len,
INT32  flags 
)

send a message on a socket

This function should be invoked to send data using the specified socket. Depending on the socket configuration, this function can perform in a blocking or non-blocking mode. In case of blocking, this function will not return until data is sent (not neccessarily all requested data). In case of non-blocking, this function will send the data using only the stack available resources and will not wait for resources to be free

Parameters
[in]sspecifies the file descriptor of the socket
[in]bufpointer to a buffer containing the message to be sent
[in]lennumber of bytes to send
[in]flagsonly 0 supported
Returns
number of characters sent. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_send_to()

INT32 m2mb_socket_bsd_send_to ( M2MB_SOCKET_BSD_SOCKET  s,
const void *  buf,
INT32  len,
INT32  flags,
const struct M2MB_SOCKET_BSD_SOCKADDR to,
INT32  tolen 
)

send a message on a socket

This function should be invoked to send data using the specified socket. Depending on the socket configuration, this function can perform in a blocking or non-blocking mode. In case of blocking, this function will not return until data is sent (not neccessarily all requested data). In case of non-blocking, this function will send the data using only the stack available resources and will not wait for resources to be free

Parameters
[in]sspecifies the file descriptor of the socket
[in]bufpointer to a buffer containing message to be sent
[in]lennumber of bytes to send
[in]flagsonly 0 supported
[in]topoints to a sockaddr structure containing the peer address. The length and format of the address depend on the address family of the socket
[in]tolenspecifies the length of the sockaddr structure pointed to by to
Returns
number of characters sent. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_set_sock_opt()

INT32 m2mb_socket_bsd_set_sock_opt ( M2MB_SOCKET_BSD_SOCKET  s,
INT32  level,
INT32  optname,
const void *  optval,
INT32  optlen 
)

set options on sockets

This function is used to set a particular socket option for the specified socket, see m2mb_socket_option_flags socket options

Parameters
[in]sspecifies the file descriptor of the socket
[in]levelprotocol level the option exists at
[in]optnamename of the option
[in]optvalpointer to a buffer with the requested option to be set
[in]optlenoption length in bytes
Returns
On success, 0 is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_bsd_socket()

M2MB_SOCKET_BSD_SOCKET m2mb_socket_bsd_socket ( INT32  domain,
INT32  type,
INT32  protocol 
)

create an endpoint for communication

creates an unbound socket in a communications domain, and returns a file descriptor that can be used in later function calls that operate on socket

Parameters
[in]domainspecifies the communications domain in which a socket is to be created: M2MB_SOCKET_BSD_AF_INET - IPv4 Internet protocols M2MB_SOCKET_BSD_AF_INET6 - IPv6 Internet protocols
[in]typespecifies the type of socket to be created: M2MB_SOCKET_BSD_SOCK_STREAM - TCP M2MB_SOCKET_BSD_SOCK_DGRAM - UDP
[in]protocolspecifies a particular protocol to be used with the socket: M2MB_SOCKET_BSD_IPPROTO_TCP M2MB_SOCKET_BSD_IPPROTO_UDP specifying a protocol of 0 causes m2mb_socket_bsd_socket() to use an unspecified default protocol appropriate for the requested socket type
Returns
On success, a handle for the new socket is returned. On error, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_socket_errno()

INT32 m2mb_socket_errno ( void  )

Gets the last error occured.

Gets the last error occured. Should be on a thread bases

Parameters
[in]

◆ m2mb_socket_set_cid()

INT32 m2mb_socket_set_cid ( M2MB_SOCKET_BSD_SOCKET  s,
UINT8  cid 
)

link a socket to a cid

specifies the PDP context to be used for transferring data on the socket

Parameters
[in]sspecifies the file descriptor of the socket
[in]cidPDP context to be used
Returns
on success, 0 is returned. On error, -1 is returned
Note
This API is implemented through a bind() of the socket to the local IP address. Therefore, a call to this API and m2mb_socket_bsd_bind() can lead to an error. If m2mb_socket_bsd_bind() is needed, it is suggested to avoid m2mb_socket_set_cid() and call only m2mb_socket_bsd_bind(), with the local IP related to the specified cid. The local IP address can be obtained through m2mb_pdp_get_my_ip( handle,cid... ).

if( m2mb_socket_set_cid( fd, cid ) == -1 )

INT32 fd;
UINT8 cid;
M2MB_RESULT_E res = M2MB_RESULT_SUCCESS;
fd = m2mb_socket_bsd_socket( M2MB_SOCKET_BSD_PF_INET,
M2MB_SOCKET_BSD_SOCK_STREAM,
M2MB_SOCKET_BSD_IPPROTO_TCP );
if( 0 < fd )
{
if( m2mb_socket_set_cid( fd, cid ) == -1 )
{
m2mb_trace_printf( M2MB_TC_FTPC, M2MB_TL_ERROR, "set cid returned error" );
ret = M2MB_RESULT_FAIL;
}
}
return ret;
m2mb_socket_bsd_socket
M2MB_SOCKET_BSD_SOCKET m2mb_socket_bsd_socket(INT32 domain, INT32 type, INT32 protocol)
create an endpoint for communication
m2mb_socket_set_cid
INT32 m2mb_socket_set_cid(M2MB_SOCKET_BSD_SOCKET s, UINT8 cid)
link a socket to a cid