libgpac
Documentation of the core library of GPAC
|
Sockets (TCP, UDP unicast, multicast) More...
Macros | |
#define | GF_MAX_IP_NAME_LEN 1025 |
#define | GF_SOCK_TYPE_TCP 0x01 |
#define | GF_SOCK_TYPE_UDP 0x02 |
Enumerations | |
enum | { GF_SOCK_REUSE_PORT = 1 , GF_SOCK_FORCE_IPV6 = 1<<1 , GF_SOCK_IS_SENDER = 1<<2 } |
enum | GF_SockSelectMode { GF_SK_SELECT_BOTH =0 , GF_SK_SELECT_READ , GF_SK_SELECT_WRITE } |
Functions | |
GF_Socket * | gf_sk_new (u32 SocketType) |
socket constructor More... | |
GF_Socket * | gf_sk_new_ex (u32 SocketType, const char *netcap_id) |
socket constructor More... | |
void | gf_sk_del (GF_Socket *sock) |
socket destructor More... | |
void | gf_sk_reset (GF_Socket *sock) |
reset internal buffer More... | |
GF_Err | gf_sk_set_buffer_size (GF_Socket *sock, Bool send_buffer, u32 new_size) |
socket buffer size control More... | |
GF_Err | gf_sk_set_block_mode (GF_Socket *sock, Bool NonBlockingOn) |
blocking mode control More... | |
GF_Err | gf_sk_bind (GF_Socket *sock, const char *local_ip, u16 port, const char *peer_name, u16 peer_port, u32 options) |
socket binding More... | |
GF_Err | gf_sk_connect (GF_Socket *sock, const char *peer_name, u16 port, const char *local_ip) |
connects a socket More... | |
GF_Err | gf_sk_send (GF_Socket *sock, const u8 *buffer, u32 length) |
data emission More... | |
GF_Err | gf_sk_send_ex (GF_Socket *sock, const u8 *buffer, u32 length, u32 *written) |
data emission More... | |
GF_Err | gf_sk_receive (GF_Socket *sock, u8 *buffer, u32 length, u32 *read) |
data reception More... | |
GF_Err | gf_sk_listen (GF_Socket *sock, u32 max_conn) |
socket listening More... | |
GF_Err | gf_sk_accept (GF_Socket *sock, GF_Socket **new_conn) |
socket accept More... | |
GF_Err | gf_sk_server_mode (GF_Socket *sock, Bool server_on) |
server socket mode More... | |
GF_Err | gf_sk_get_host_name (char *buffer) |
get local host name More... | |
GF_Err | gf_sk_get_local_ip (GF_Socket *sock, char *buffer) |
get local IP More... | |
GF_Err | gf_sk_get_local_info (GF_Socket *sock, u16 *port, u32 *sock_type) |
get local info More... | |
GF_Err | gf_sk_get_remote_address (GF_Socket *sock, char *buffer) |
get remote address More... | |
GF_Err | gf_sk_get_remote_address_port (GF_Socket *sock, char *buffer, u32 *port) |
get remote address More... | |
GF_Err | gf_sk_set_remote (GF_Socket *sock, char *address, u16 port) |
set remote address More... | |
GF_Err | gf_sk_setup_multicast (GF_Socket *sock, const char *multi_ip_add, u16 multi_port, u32 TTL, Bool no_bind, const char *ifce_ip_or_name) |
multicast setup More... | |
GF_Err | gf_sk_setup_multicast_ex (GF_Socket *sock, const char *multi_ip_add, u16 multi_port, u32 TTL, Bool no_bind, const char *ifce_ip_or_name, const char **src_ip_inc, u32 nb_src_ip_inc, const char **src_ip_exc, u32 nb_src_ip_exc) |
source-specific multicast setup More... | |
u32 | gf_sk_is_multicast_address (const char *multi_ip_add) |
multicast address test More... | |
s32 | gf_sk_get_handle (GF_Socket *sock) |
gets socket handle More... | |
void | gf_sk_set_usec_wait (GF_Socket *sock, u32 usec_wait) |
GF_Err | gf_sk_receive_no_select (GF_Socket *sock, u8 *buffer, u32 length, u32 *read) |
GF_Err | gf_sk_probe (GF_Socket *sock) |
char * | gf_net_bump_ip_address (const char *in_ip, u32 increment) |
Bool | gf_net_get_adapter_ip (const char *ip_or_name, char **ipv4, char **ipv6) |
GF_Err | gf_sk_select (GF_Socket *sock, GF_SockSelectMode mode) |
#define GF_MAX_IP_NAME_LEN 1025 |
Buffer size to pass for IP address retrieval
#define GF_SOCK_TYPE_TCP 0x01 |
socket is a TCP socket
#define GF_SOCK_TYPE_UDP 0x02 |
socket is a UDP socket
anonymous enum |
enum GF_SockSelectMode |
GF_Socket* gf_sk_new | ( | u32 | SocketType | ) |
Constructs a socket object
SocketType | the socket type to create, either UDP or TCP |
GF_Socket* gf_sk_new_ex | ( | u32 | SocketType, |
const char * | netcap_id | ||
) |
Constructs a socket object with a specific netcap configuration ID
SocketType | the socket type to create, either UDP or TCP |
netcap_id | ID of netcap configuration to use, may be null (see gpac -h netcap) |
void gf_sk_del | ( | GF_Socket * | sock | ) |
Deletes a socket object
sock | the socket object |
void gf_sk_reset | ( | GF_Socket * | sock | ) |
Forces the internal socket buffer to be reseted (discarded)
sock | the socket object |
Sets the size of the internal buffer of the socket. The socket MUST be bound or connected before.
sock | the socket object |
send_buffer | if 0, sets the size of the reception buffer, otherwise sets the size of the emission buffer |
new_size | new size of the buffer in bytes. |
Sets the blocking mode of a socket on or off. A blocking socket will wait for the net operation to be possible while a non-blocking one would return an error. By default, sockets are created in blocking mode
sock | the socket object |
NonBlockingOn | set to 1 to use non-blocking sockets, 0 otherwise |
GF_Err gf_sk_bind | ( | GF_Socket * | sock, |
const char * | local_ip, | ||
u16 | port, | ||
const char * | peer_name, | ||
u16 | peer_port, | ||
u32 | options | ||
) |
Binds the given socket to the specified port.
local_ip | the local interface IP address if desired. If NULL, the default interface will be used. |
sock | the socket object |
port | port number to bind this socket to |
peer_name | the remote server address, if NULL, will use localhost |
peer_port | remote port number to connect the socket to |
options | list of option for the bind operation. |
Connects a socket to a remote peer on a given port
sock | the socket object |
peer_name | the remote server address (IP or DNS) |
port | remote port number to connect the socket to |
local_ip | the local (client) address (IP or DNS) if any, NULL otherwise. |
Sends a buffer on the socket. The socket must be in a bound or connected mode
sock | the socket object |
buffer | the data buffer to send |
length | the data length to send |
Sends a buffer on the socket. The socket must be in a bound or connected mode. This function is usually needed for non-blocking sockets
sock | the socket object |
buffer | the data buffer to send |
length | the data length to send |
written | set to number of written bytes - may be NULL |
Fetches data on a socket. The socket must be in a bound or connected state
sock | the socket object |
buffer | the reception buffer where data is written. Passing NULL will only probe for data in socket (eg only do select() ). |
length | the allocated size of the reception buffer |
read | the actual number of bytes received |
Sets the socket in a listening state. This socket must have been bound to a port before
sock | the socket object |
max_conn | the maximum number of simultaneous connection this socket will accept |
GF_Err gf_sk_accept | ( | GF_Socket * | sock, |
GF_Socket ** | new_conn | ||
) |
Accepts an incoming connection on a listening socket
sock | the socket object |
new_conn | the resulting connection socket object |
Disable the Nable algo (e.g. set TCP_NODELAY) and set the KEEPALIVE on
sock | the socket object |
server_on | sets server mode on or off |
GF_Err gf_sk_get_host_name | ( | char * | buffer | ) |
Retrieves local host name.
buffer | destination buffer for name. Buffer must be GF_MAX_IP_NAME_LEN long |
GF_Err gf_sk_get_local_ip | ( | GF_Socket * | sock, |
char * | buffer | ||
) |
Gets local IP address of a connected socket, typically used for server after an ACCEPT
sock | the socket object |
buffer | destination buffer for IP address. Buffer must be GF_MAX_IP_NAME_LEN long |
Gets local socket info of a socket
sock | the socket object |
port | local port number of the socket |
sock_type | socket type (UDP or TCP) |
GF_Err gf_sk_get_remote_address | ( | GF_Socket * | sock, |
char * | buffer | ||
) |
Gets the remote address of a peer. The socket MUST be connected.
sock | the socket object |
buffer | destination buffer for IP address. Buffer must be GF_MAX_IP_NAME_LEN long |
Gets the remote address and port of a peer. The socket MUST be connected.
sock | the socket object |
buffer | destination buffer for IP address. Buffer must be GF_MAX_IP_NAME_LEN long |
port | set to the remote port, may be NULL |
Sets the remote address of a socket. This is used by connectionless sockets using SendTo and ReceiveFrom
sock | the socket object |
address | the remote peer address |
port | the remote peer port |
GF_Err gf_sk_setup_multicast | ( | GF_Socket * | sock, |
const char * | multi_ip_add, | ||
u16 | multi_port, | ||
u32 | TTL, | ||
Bool | no_bind, | ||
const char * | ifce_ip_or_name | ||
) |
Performs multicast setup (BIND and JOIN) for the socket object
sock | the socket object |
multi_ip_add | the multicast IP address |
multi_port | the multicast port number |
TTL | the multicast TTL (Time-To-Live) |
no_bind | if sets, only join the multicast |
ifce_ip_or_name | the local interface IP address or name if desired. If NULL, the default interface will be used. |
GF_Err gf_sk_setup_multicast_ex | ( | GF_Socket * | sock, |
const char * | multi_ip_add, | ||
u16 | multi_port, | ||
u32 | TTL, | ||
Bool | no_bind, | ||
const char * | ifce_ip_or_name, | ||
const char ** | src_ip_inc, | ||
u32 | nb_src_ip_inc, | ||
const char ** | src_ip_exc, | ||
u32 | nb_src_ip_exc | ||
) |
Performs multicast setup (BIND and JOIN) for the socket object using allowed and block sources
sock | the socket object |
multi_ip_add | the multicast IP address |
multi_port | the multicast port number |
TTL | the multicast TTL (Time-To-Live) |
no_bind | if sets, only join the multicast |
ifce_ip_or_name | the local interface IP address or name if desired. If NULL, the default interface will be used. |
src_ip_inc | IP of sources to receive from |
nb_src_ip_inc | number of sources to receive from |
src_ip_exc | IP of sources to exclude |
nb_src_ip_exc | number of sources to exclude |
u32 gf_sk_is_multicast_address | ( | const char * | multi_ip_add | ) |
Tests whether an IP address is a multicast one or not
multi_ip_add | the multicast IP address to test |
s32 gf_sk_get_handle | ( | GF_Socket * | sock | ) |
Gets the socket low-level handle as used by OpenSSL.
sock | the socket object |
void gf_sk_set_usec_wait | ( | GF_Socket * | sock, |
u32 | usec_wait | ||
) |
Sets the socket wait time in microseconds. Default wait time is 500 microseconds. Any value >= 1000000 will reset to default.
sock | the socket object |
usec_wait | wait time in microseconds |
Fetches data on a socket without performing any select (wait), to be used with socket group on sockets that are set in the selected socket group
sock | the socket object |
buffer | the reception buffer where data is written |
length | the allocated size of the reception buffer |
read | the actual number of bytes received |
GF_Err gf_sk_probe | ( | GF_Socket * | sock | ) |
Checks if connection has been closed by remote peer
sock | the socket object |
char* gf_net_bump_ip_address | ( | const char * | in_ip, |
u32 | increment | ||
) |
Bumps lower part of IP address by the given increment eg X.X.X.Y -> X.X.X.Z with Z=Y+increment
in_ip | the input IP v4 or v6 address |
increment | the increment to apply |
Bool gf_net_get_adapter_ip | ( | const char * | ip_or_name, |
char ** | ipv4, | ||
char ** | ipv6 | ||
) |
Gets IP associated with an interface
ip_or_name | the input interface name or IP v4 or v6 address |
ipv4 | set t o v4 address - can be NULL but shall be freed by user |
ipv6 | set t o v6 address - can be NULL but shall be freed by user |
GF_Err gf_sk_select | ( | GF_Socket * | sock, |
GF_SockSelectMode | mode | ||
) |
Checks if socket can is ready for read or write
sock | the socket object |
mode | the operation mode desired |