Functions for establishing and managing low level sockets. More...
#include <freeradius-devel/libradius.h>
#include <freeradius-devel/udpfromto.h>
#include <fcntl.h>
Go to the source code of this file.
Functions | |
int | fr_socket_client_tcp (fr_ipaddr_t *src_ipaddr, fr_ipaddr_t *dst_ipaddr, uint16_t dst_port, bool async) |
Establish a connected TCP socket. More... | |
int | fr_socket_client_udp (fr_ipaddr_t *src_ipaddr, fr_ipaddr_t *dst_ipaddr, uint16_t dst_port, bool async) |
Establish a connected UDP socket. More... | |
int | fr_socket_client_unix (UNUSED char const *path, UNUSED bool async) |
int | fr_socket_server_base (int proto, fr_ipaddr_t *ipaddr, int *port, char const *port_name, bool async) |
Open an IPv4 / IPv6, and UDP / TCP socket, server side. More... | |
int | fr_socket_server_bind (int sockfd, fr_ipaddr_t *ipaddr, int *port, char const *interface) |
Bind to an IPv4 / IPv6, and UDP / TCP socket, server side. More... | |
int | fr_socket_wait_for_connect (int sockfd, struct timeval const *timeout) |
Wait for a socket to be connected, with an optional timeout. More... | |
Functions for establishing and managing low level sockets.
Definition in file socket.c.
int fr_socket_client_tcp | ( | fr_ipaddr_t * | src_ipaddr, |
fr_ipaddr_t * | dst_ipaddr, | ||
uint16_t | dst_port, | ||
bool | async | ||
) |
Establish a connected TCP socket.
The following code demonstrates using this function with a connection timeout:
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 167 of file socket.c.
int fr_socket_client_udp | ( | fr_ipaddr_t * | src_ipaddr, |
fr_ipaddr_t * | 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:
src_ipaddr | to bind socket to, may be NULL if socket is not bound to any specific address. |
dst_ipaddr | Where to send datagrams. |
dst_port | Where to send datagrams. |
async | Whether to set the socket to nonblocking, allowing use of fr_socket_wait_for_connect. |
Definition at line 273 of file socket.c.
int fr_socket_server_base | ( | int | proto, |
fr_ipaddr_t * | ipaddr, | ||
int * | port, | ||
char const * | port_name, | ||
bool | async | ||
) |
Open an IPv4 / IPv6, and UDP / TCP socket, server side.
[in] | proto | IPPROTO_UDP or IPPROTO_TCP |
[in] | ipaddr | The IP address to listen on |
[in,out] | port | the port to listen on |
[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 422 of file socket.c.
int fr_socket_server_bind | ( | int | sockfd, |
fr_ipaddr_t * | ipaddr, | ||
int * | port, | ||
char const * | interface | ||
) |
Bind to an IPv4 / IPv6, and UDP / TCP socket, server side.
[in] | sockfd | the socket which was opened via fr_socket_server_base() |
[in,out] | ipaddr | The IP address to bind to |
[in] | port | the port to bind to |
[in] | interface | the interface name to bind to |
Definition at line 615 of file socket.c.
int fr_socket_wait_for_connect | ( | int | sockfd, |
struct timeval const * | 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 359 of file socket.c.