Socket and network address interface. More...
#include <sofia-sip/su_config.h>
#include <sofia-sip/su_types.h>
#include <sofia-sip/su_errno.h>
#include <stdio.h>
#include <limits.h>
#include <sofia-sip/su_addrinfo.h>
Go to the source code of this file.
Data Structures | |
union | su_sockaddr_u |
Common socket address structure. More... | |
struct | su_iovec_s |
I/O vector for scatter-gather I/O. More... | |
Defines | |
#define | SU_H |
Defined when <sofia-sip/su.h> has been included. | |
#define | SU_MAXHOST |
Maximum size of host name. | |
#define | SU_MAXSERV |
Maximum size of service name. | |
#define | SU_ADDRSIZE |
Maximum size of address in text format. | |
#define | SU_SERVSIZE |
Maximum size of port number in text format. | |
#define | SU_IOVECLEN_MAX |
Maximum size of buffer in a single su_iovec_t element. | |
#define | SU_ADDR(su) |
Get pointer to address field. | |
#define | SU_ADDRLEN(su) |
Get length of address field. | |
#define | SU_HAS_INADDR_ANY(su) |
Test if su_sockaddr_t is INADDR_ANY or IN6ADDR_ANY. | |
#define | SU_SOCKADDR_SIZE(su) |
Calculate correct size of su_sockaddr_t structure. | |
Typedefs | |
typedef int | su_socket_t |
Socket descriptor type. | |
typedef size_t | su_ioveclen_t |
Type of siv_len field in su_iovec_t. | |
typedef struct su_iovec_s | su_iovec_t |
I/O vector for scatter-gather I/O. | |
Enumerations | |
enum | { INVALID_SOCKET, INVALID_SOCKET } |
Functions | |
int | su_init (void) |
Initialize socket implementation. | |
void | su_deinit (void) |
Deinitialize socket implementation. | |
su_socket_t | su_socket (int af, int sock, int proto) |
Create an endpoint for communication. | |
int | su_close (su_socket_t s) |
Close an socket descriptor. | |
int | su_ioctl (su_socket_t s, int request,...) |
Control socket. | |
int | su_is_blocking (int errcode) |
Check for in-progress error codes. | |
int | su_setblocking (su_socket_t s, int blocking) |
Set/reset blocking option. | |
int | su_setreuseaddr (su_socket_t s, int reuse) |
Set/reset address reusing option. | |
int | su_soerror (su_socket_t s) |
Get the error code associated with the socket. | |
int | su_getsocktype (su_socket_t s) |
Get the socket type. | |
issize_t | su_getmsgsize (su_socket_t s) |
Get size of message available in socket. | |
issize_t | su_vsend (su_socket_t, su_iovec_t const iov[], isize_t len, int flags, su_sockaddr_t const *su, socklen_t sulen) |
Scatter-gather send. | |
issize_t | su_vrecv (su_socket_t, su_iovec_t iov[], isize_t len, int flags, su_sockaddr_t *su, socklen_t *sulen) |
Scatter-gather receive. | |
int | su_getlocalip (su_sockaddr_t *sin) |
Return local IP address. | |
int | su_cmp_sockaddr (su_sockaddr_t const *a, su_sockaddr_t const *b) |
Compare two socket addresses. | |
int | su_match_sockaddr (su_sockaddr_t const *a, su_sockaddr_t const *b) |
Check if socket address b match with a. | |
void | su_canonize_sockaddr (su_sockaddr_t *su) |
Convert mapped/compat address to IPv4 address. |
Socket and network address interface.
#define SU_ADDR | ( | su | ) |
Get pointer to address field.
The macro SU_ADDR() returns pointer to the address field (sin_data, sin_addr or sin_addr6, depending on the address family).
#define SU_ADDRLEN | ( | su | ) |
Get length of address field.
The macro SU_ADDRLEN() returns length of the address field (sin_data, sin_addr or sin_addr6, depending on the address family).
#define SU_ADDRSIZE |
Maximum size of address in text format.
#define SU_H |
Defined when <sofia-sip/su.h> has been included.
#define SU_HAS_INADDR_ANY | ( | su | ) |
Test if su_sockaddr_t is INADDR_ANY or IN6ADDR_ANY.
#define SU_IOVECLEN_MAX |
Maximum size of buffer in a single su_iovec_t element.
#define SU_MAXHOST |
Maximum size of host name.
#define SU_MAXSERV |
Maximum size of service name.
#define SU_SERVSIZE |
Maximum size of port number in text format.
#define SU_SOCKADDR_SIZE | ( | su | ) |
Calculate correct size of su_sockaddr_t structure.
typedef struct su_iovec_s su_iovec_t |
I/O vector for scatter-gather I/O.
This is the I/O vector element used with su_vsend() and su_vrecv(). It is defined like struct iovec with POSIX sockets:
struct iovec { void *iov_base; // Pointer to data. size_t iov_len; // Length of data. };
When using WINSOCK sockets it is defined as WSABUF:
typedef struct __WSABUF { u_long len; char FAR* buf; } WSABUF, *LPWSABUF;
For historical reasons, the structure is known as msg_iovec_t in msg module.
struct
iovec
defined in <sys/uio.h>, writev(2), readv(2), sendmsg(), recvmsg(), WSABUF of WinSock2 typedef size_t su_ioveclen_t |
Type of siv_len field in su_iovec_t.
The siv_len field in su_iovec_t has different types in with POSIX (size_t) and WINSOCK2 (u_long). Truncate the iovec element size to SU_IOVECLEN_MAX, if needed, and cast using su_ioveclen_t.
typedef int su_socket_t |
Socket descriptor type.
anonymous enum |
int su_close | ( | su_socket_t | s | ) |
Close an socket descriptor.
void su_deinit | ( | void | ) |
Deinitialize socket implementation.
int su_getlocalip | ( | su_sockaddr_t * | sa | ) |
issize_t su_getmsgsize | ( | su_socket_t | s | ) |
Get size of message available in socket.
int su_getsocktype | ( | su_socket_t | s | ) |
Get the socket type.
int su_init | ( | void | ) |
Initialize socket implementation.
Before using any sofia-sip-ua functions, the application should call su_init() in order to initialize run-time environment including sockets. This function may prepare plugins if there are any.
int su_ioctl | ( | su_socket_t | s, | |
int | request, | |||
... | ||||
) |
Control socket.
int su_is_blocking | ( | int | errcode | ) |
Check for in-progress error codes.
Checks if the errcode indicates that the socket call failed because it would have blocked.
Defined as macro with POSIX sockets.
int su_match_sockaddr | ( | su_sockaddr_t const * | a, | |
su_sockaddr_t const * | b | |||
) |
Check if socket address b match with a.
The function su_match_sockaddr() returns true if the socket address b matches with the socket address a. This happens if either all the interesting fields are identical: address family, port number, address, and scope ID (in case of IPv6) or that the a contains a wildcard (zero) in their place.
int su_setblocking | ( | su_socket_t | s, | |
int | blocking | |||
) |
Set/reset blocking option.
int su_setreuseaddr | ( | su_socket_t | s, | |
int | reuse | |||
) |
Set/reset address reusing option.
su_socket_t su_socket | ( | int | af, | |
int | socktype, | |||
int | proto | |||
) |
Create an endpoint for communication.
Create an endpoint for communication.
af | addressing family | |
socktype | socket type | |
proto | protocol number specific to the addressing family |
The newly created socket is nonblocking unless global variable su_socket_blocking is set to true.
Also, the newly created socket is closed on exec() if global variable su_socket_close_on_exec is set to true. Note that a multithreaded program can fork() and exec() before the close-on-exec flag is set.
int su_soerror | ( | su_socket_t | s | ) |
Get the error code associated with the socket.
issize_t su_vrecv | ( | su_socket_t | s, | |
su_iovec_t | iov[], | |||
isize_t | iovlen, | |||
int | flags, | |||
su_sockaddr_t * | su, | |||
socklen_t * | sulen | |||
) |
Scatter-gather receive.
issize_t su_vsend | ( | su_socket_t | s, | |
su_iovec_t const | iov[], | |||
isize_t | iovlen, | |||
int | flags, | |||
su_sockaddr_t const * | su, | |||
socklen_t | sulen | |||
) |
Scatter-gather send.