![]() |
m2mb API docs
25.21.003
m2mb API sets documentation
|
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 |
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... | |
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>
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | name | it is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket |
| [in] | namelen | it 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 |
Example
| 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
| [in] | s | specifies the file descriptor of the socket to be bound |
| [in] | name | points 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] | namelen | specifies the length of the sockaddr structure pointed to by name |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | name | points 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] | namelen | specifies the length of the sockaddr structure pointed to by name |
Example
| 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
| [in] | fd | file descriptor |
| [in] | set | set of file descriptors |
Example
| 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
| [in] | fd | file descriptor |
| [in] | set | set of file descriptors |
Example
| 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
| [in] | fd | file descriptor |
| [in] | set | set of file descriptors |
Example
| 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
| [in] | set | set of file descriptors |
Example
| 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
| [in] | name | either a hostname, or an IPv4 address in standard dot notation or an IPv6 address in colon notation |
| [in] | af | address family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6 |
| [in] | ret | pre-allocated struct where to store the result |
| [in] | buf | pre-allocated buffer where to store additional data |
| [in] | buflen | the size of buf |
| [in] | result | pointer to a hostent pointer that is set to ret on success and set to zero on error |
| [in] | h_errnop | pointer to an int where to store errors (instead of modifying the global h_errno) |
| [in] | cid | PDP context to be used |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | name | is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket |
| [in] | namelen | it 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 |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | name | is a pointer to a sockaddr structure. This structure is filled in with the local address of the socket |
| [in] | namelen | it 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 |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | level | protocol level the option exists at |
| [in] | optname | name of the option |
| [in] | optval | pointer to a buffer in which the value for the requested option is to be returned |
| [in] | optlen | option length in bytes |
Example
| 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.
| [in] | x | unsigned integer to be converted |
Example
| 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
| [in] | x | unsigned short integer to be converted |
Example
| 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
| [in] | af | Address family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6 |
| [in] | src | Pointer to IPv4 or IPv6 address |
| [in] | dst | Pointer to output buffer to contain IPv4/IPv6 address string |
| [in] | size | Size of output buffer in bytes |
Example
| 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
| [in] | af | Address family. M2MB_SOCKET_BSD_AF_INET for IPv4, M2MB_SOCKET_BSD_AF_INET6 for IPv6 |
| [in] | src | IPv4 or IPv6 address string (null-terminated) |
| [in] | dst | Resulting IPv4/IPv6 address: struct M2MB_SOCKET_BSD_IN_ADDR in case of IPv4, struct M2MB_SOCKET_BSD_IPV6_ADDR in case of IPv6 |
Example
| 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)
| [in] | cmd | name of the command: M2MB_SOCKET_BSD_FIONREAD,M2MB_SOCKET_BSD_FIONBIO |
| [in] | argp | pointer to the value (input parameter or output parameter) |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | backlog | defines the maximum length to which the queue of pending connections for s may grow |
Example
| 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.
| [in] | x | unsigned integer to be converted |
Example
| 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
| [in] | x | unsigned short integer to be converted |
Example
| 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)
| [in] | s | specifies the file descriptor of the socket |
| [in] | buf | Pointer to a buffer for received message |
| [in] | len | Number of bytes to receive |
| [in] | flags | only 0 supported |
Example
| 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)
| [in] | s | specifies the file descriptor of the socket |
| [in] | buf | Pointer to a buffer for received message |
| [in] | len | Number of bytes to receive |
| [in] | flags | only 0 supported |
| [in] | from | is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket |
| [in] | fromlen | it 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 |
Example
| 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
| [in] | nfds | nfds is the highest-numbered file descriptor in any of the three sets, plus 1 |
| [in] | readfds | set 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] | writefds | set 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] | exceptfds | set 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] | timeout | specifies the minimum interval that m2mb_socket_bsd_select() should block waiting for a file descriptor to become ready |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | buf | pointer to a buffer containing the message to be sent |
| [in] | len | number of bytes to send |
| [in] | flags | only 0 supported |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | buf | pointer to a buffer containing message to be sent |
| [in] | len | number of bytes to send |
| [in] | flags | only 0 supported |
| [in] | to | points to a sockaddr structure containing the peer address. The length and format of the address depend on the address family of the socket |
| [in] | tolen | specifies the length of the sockaddr structure pointed to by to |
Example
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | level | protocol level the option exists at |
| [in] | optname | name of the option |
| [in] | optval | pointer to a buffer with the requested option to be set |
| [in] | optlen | option length in bytes |
Example
| 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
| [in] | domain | specifies 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] | type | specifies the type of socket to be created: M2MB_SOCKET_BSD_SOCK_STREAM - TCP M2MB_SOCKET_BSD_SOCK_DGRAM - UDP |
| [in] | protocol | specifies 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 |
Example
| INT32 m2mb_socket_errno | ( | void | ) |
Gets the last error occured.
Gets the last error occured. Should be on a thread bases
| [in] |
| 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
| [in] | s | specifies the file descriptor of the socket |
| [in] | cid | PDP context to be used |
if( m2mb_socket_set_cid( fd, cid ) == -1 )