The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Functions for establishing and managing low level sockets. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/socket.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/udpfromto.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/cap.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <ifaddrs.h>
Go to the source code of this file.
Functions | |
int | fr_socket_bind (int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port) |
Bind a UDP/TCP v4/v6 socket to a given ipaddr src port, and interface. | |
int | fr_socket_client_tcp (char const *ifname, fr_ipaddr_t *src_ipaddr, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, bool async) |
Establish a connected TCP socket. | |
int | fr_socket_client_udp (char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, bool async) |
Establish a connected UDP socket. | |
int | fr_socket_client_unix (UNUSED char const *path, UNUSED bool async) |
int | fr_socket_server_tcp (fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, char const *port_name, bool async) |
Open an IPv4/IPv6 TCP socket. | |
int | fr_socket_server_udp (fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, char const *port_name, bool async) |
Open an IPv4/IPv6 unconnected UDP socket. | |
int | fr_socket_wait_for_connect (int sockfd, fr_time_delta_t timeout) |
Wait for a socket to be connected, with an optional timeout. | |
static int | socket_bind_ifname (UNUSED int sockfd, UNUSED char const *ifname) |
static int | socket_dont_fragment (UNUSED int sockfd, UNUSED int af) |
static | socket_dont_inherit (UNUSED int sockfd) |
static int | socket_inaddr_any_v6only (UNUSED int sockfd, UNUSED fr_ipaddr_t const *ipaddr) |
static int | socket_port_from_service (int proto, char const *port_name) |
Resolve a named service to a port. | |
Functions for establishing and managing low level sockets.
Definition in file socket.c.
int fr_socket_bind | ( | int | sockfd, |
char const * | ifname, | ||
fr_ipaddr_t * | src_ipaddr, | ||
uint16_t * | src_port | ||
) |
Bind a UDP/TCP v4/v6 socket to a given ipaddr src port, and interface.
Use one of:
[in] | sockfd | the socket which opened by fr_socket_server_*. |
[in] | ifname | to bind to. |
[in,out] | src_ipaddr | The IP address to bind to. Will be updated to the IP address that was actually bound to. Pass NULL to just bind to an interface. |
[in] | src_port | the port to bind to. NULL if any port is allowed. |
Definition at line 229 of file socket.c.
int fr_socket_client_tcp | ( | char const * | ifname, |
fr_ipaddr_t * | src_ipaddr, | ||
fr_ipaddr_t const * | dst_ipaddr, | ||
uint16_t | dst_port, | ||
bool | async | ||
) |
Establish a connected TCP socket.
The following code demonstrates using this function with a connection timeout:
[in] | ifname | If non-NULL, bind the socket to this interface. |
src_ipaddr | to bind socket to, may be NULL if socket is not bound to any specific address. | |
dst_ipaddr | Where to connect to. | |
dst_port | Where to connect to. | |
async | Whether to set the socket to nonblocking, allowing use of fr_socket_wait_for_connect. |
Definition at line 729 of file socket.c.
int fr_socket_client_udp | ( | char const * | ifname, |
fr_ipaddr_t * | src_ipaddr, | ||
uint16_t * | src_port, | ||
fr_ipaddr_t const * | dst_ipaddr, | ||
uint16_t | dst_port, | ||
bool | async | ||
) |
Establish a connected UDP socket.
Connected UDP sockets can be used with write(), unlike unconnected sockets which must be used with sendto and recvfrom.
The following code demonstrates using this function with a connection timeout:
[in] | ifname | If non-NULL, bind the socket to this interface. |
[in,out] | src_ipaddr | to bind socket to, may be NULL if socket is not bound to any specific address. If non-null, the bound IP is copied here, too. |
[out] | src_port | The source port we were bound to, may be NULL. |
[in] | dst_ipaddr | Where to send datagrams. |
[in] | dst_port | Where to send datagrams. |
[in] | async | Whether to set the socket to nonblocking, allowing use of fr_socket_wait_for_connect. |
Definition at line 634 of file socket.c.
int fr_socket_server_tcp | ( | fr_ipaddr_t const * | src_ipaddr, |
uint16_t * | src_port, | ||
char const * | port_name, | ||
bool | async | ||
) |
Open an IPv4/IPv6 TCP socket.
[in] | src_ipaddr | The IP address to listen on |
[in,out] | src_port | the port to listen on. If *port == 0, the resolved service port will be written here. NULL if any port is allowed. |
[in] | port_name | if *port == 0, the name of the port |
[in] | async | whether we block or not on reads and writes |
Definition at line 969 of file socket.c.
int fr_socket_server_udp | ( | fr_ipaddr_t const * | src_ipaddr, |
uint16_t * | src_port, | ||
char const * | port_name, | ||
bool | async | ||
) |
Open an IPv4/IPv6 unconnected UDP socket.
Function name is a bit of a misnomer as it can also be used to create client sockets too, such is the nature of UDP.
[in] | src_ipaddr | The IP address to listen on |
[in,out] | src_port | the port to listen on. If *port == 0, the resolved service port will be written here. |
[in] | port_name | if *port == 0, the name of the port |
[in] | async | whether we block or not on reads and writes |
Definition at line 867 of file socket.c.
int fr_socket_wait_for_connect | ( | int | sockfd, |
fr_time_delta_t | timeout | ||
) |
Wait for a socket to be connected, with an optional timeout.
close(sockfd)
.sockfd | the socket to wait on. |
timeout | How long to wait for socket to open. |
Definition at line 803 of file socket.c.
|
static |
|
static |
|
static |
Resolve a named service to a port.
[in] | proto | The protocol. Either IPPROTO_TCP or IPPROTO_UDP. |
[in] | port_name | The service name, i.e. "radius". |
Definition at line 48 of file socket.c.