LIBSSDP
 All Classes Files Functions Variables Typedefs Macros
Macros | Functions
socket_helpers.c File Reference
#include <arpa/inet.h>
#include <errno.h>
#include <ifaddrs.h>
#include <linux/version.h>
#include <netinet/in.h>
#include <net/if.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "log.h"
#include "net_definitions.h"
#include "net_utils.h"
#include "socket_helpers.h"
#include "ssdp_static_defs.h"
Include dependency graph for socket_helpers.c:

Go to the source code of this file.

Macros

#define CHECK_KERNEL_VERSION(...)   LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)
 

Functions

int set_send_timeout (SOCKET sock, int timeout)
 
int set_receive_timeout (SOCKET sock, int timeout)
 
int set_reuseaddr (SOCKET sock)
 
int set_reuseport (SOCKET sock)
 
int set_keepalive (SOCKET sock, BOOL keepalive)
 
int set_ttl (SOCKET sock, int family, int ttl)
 
int disable_multicast_loopback (SOCKET sock, int family)
 
int join_multicast_group (SOCKET sock, char *multicast_group, char *interface_ip)
 
SOCKET setup_socket (socket_conf_s *conf)
 

Detailed Description

Helper functions for creating and configuring sockets.

Definition in file socket_helpers.c.

Function Documentation

int disable_multicast_loopback ( SOCKET  sock,
int  family 
)

Disable multicast loopback traffic for a socket.

Parameters
sockThe socket to disable it for.
familySocket IP type (AF_INET or AF_INET6).
Returns
0 on success, errno otherwise.

Definition at line 118 of file socket_helpers.c.

int join_multicast_group ( SOCKET  sock,
char *  multicast_group,
char *  interface_ip 
)

Join a multicast group.

Parameters
multicast_groupThe group to join.
interface_ipThe interface to join on.
Returns
0 on success, errno otherwise.

Definition at line 135 of file socket_helpers.c.

int set_keepalive ( SOCKET  sock,
BOOL  keepalive 
)

Set the keepalive for a socket.

Parameters
sockThe socket to enable keepalive for.
keepaliveTRUE to enable keepalive for this socket, FALSE to disable it.
Returns
0 on success, errno otherwise.

Definition at line 93 of file socket_helpers.c.

int set_receive_timeout ( SOCKET  sock,
int  timeout 
)

Set the recv-timeout for a socket.

Parameters
sockThe socket to set the timeout for.
timeoutThe timeout value to set.
Returns
0 on success, errno otherwise.

Definition at line 48 of file socket_helpers.c.

int set_reuseaddr ( SOCKET  sock)

Set the reuseaddr for a socket. This enables the socket to receive from an address already in use (address and port in linux >= 3.9).

Parameters
sockThe socket to set the reuseaddr for.
Returns
0 on success, errno otherwise.

Definition at line 64 of file socket_helpers.c.

int set_reuseport ( SOCKET  sock)

Set the reuseport for a socket. This enable socket to receive from a port already in use (no support in linux < 3.9).

Parameters
sockThe socket to set the reuseport for.
Returns
0 on success, errno otherwise.

Definition at line 75 of file socket_helpers.c.

int set_send_timeout ( SOCKET  sock,
int  timeout 
)

Set the send-timeout for a socket.

Parameters
sockThe socket to set the timeout for.
timeoutThe timeout value to set.
Returns
0 on success, errno otherwise.

Definition at line 32 of file socket_helpers.c.

int set_ttl ( SOCKET  sock,
int  family,
int  ttl 
)

Set the Time-To-Live (ttl) for a socket.

Parameters
sockThe socket to set the ttl for.
ttlThe ttl value to set.
Returns
0 on success, errno otherwise.

Definition at line 103 of file socket_helpers.c.

SOCKET setup_socket ( socket_conf_s conf)

Create and configure a new socket.

Parameters
confThe socket configuration to use when creating and configuring the socket.
Returns
A new socket.

Definition at line 375 of file socket_helpers.c.