Loading...
Searching...
No Matches
su.h File Reference
Socket Functions

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>`
Include dependency graph for su.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...

## Macros

#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 , SOCKET_ERROR , SOCKET_ERROR , su_success , su_failure }

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

## Detailed Description

Socket and network address interface.

Author
  Pekka Pessi Pekka.nosp@m..Pes.nosp@m.si@no.nosp@m.kia..nosp@m.com

Date
  Created: Thu Mar 18 19:40:51 1999 pessi

## Macro Definition Documentation

## SU_ADDR

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

## SU_ADDRLEN

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

## SU_IOVECLEN_MAX

#define SU_IOVECLEN_MAX

Maximum size of buffer in a single su_iovec_t element.

See also
  su_ioveclen_t, su_iovec_t

Since
  New in 1.12.2.

## Typedef Documentation

## su_iovec_t

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;

Note
  Ordering of the fields is reversed on Windows. Do not initialize this structure with static initializer, but assign both fields separately. Note that the type of the siv_len is su_ioveclen_t which is defined as u_long on Windows and size_t on POSIX.

For historical reasons, the structure is known as msg_iovec_t in msg module.

See also
  su_ioveclen_t, SU_IOVECLEN_MAX, su_vsend(), su_vrecv(), msg_iovec_t, msg_iovec(), msg_recv_iovec(), `struct` `iovec` defined in <sys/uio.h>, writev(2), readv(2), sendmsg(), recvmsg(), WSABUF of WinSock2

## su_ioveclen_t

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.

See also
  su_iovec_t, SU_IOVECLEN_MAX

Since
  New in 1.12.2.

## Enumeration Type Documentation

## anonymous enum

anonymous enum

Enumerator
INVALID_SOCKET | Invalid socket descriptor, error from socket() or accept().
INVALID_SOCKET | Invalid socket descriptor, error from socket() or accept().
SOCKET_ERROR | Error from other socket calls.
SOCKET_ERROR | Error from other socket calls.
su_success | Return code for a successful call.
su_failure | Return code for an unsuccessful call.

## Function Documentation

## su_getlocalip()

int su_getlocalip | ( | su_sockaddr_t * | sa | ) |

Return local IP address.

Return local IP address.

Deprecated
  Use su_getlocalinfo() instead.

## su_init()

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.

POSIX Implementation
  The su_init() initializes debugging logs and ignores the SIGPIPE signal.

Windows Implementation
  The function su_init() initializes Winsock2 library on Windows.

Symbian Implementation
  The function su_init() prompts user to select an access point (interface towards Internet) and uses the activated access point for the socket operations.

## su_is_blocking()

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.

Since
  New in 1.12.2.

## su_match_sockaddr()

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.

## su_socket()

su_socket_t su_socket | ( | int | af,
|  | int | socktype,
|  | int | proto )

Create an endpoint for communication.

Create an endpoint for communication.

Parameters

  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.

Returns
  A valid socket descriptor or INVALID_SOCKET (-1) upon an error.

## su_vrecv()

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.

Scatter-gather receive.

## su_vsend()

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.

Scatter-gather send.

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.