28RCSIDH(socket_h,
"$Id: 46c241f3adc0ec015c1bf226ac60b2380d867057 $")
34#include <freeradius-devel/build.h>
35#include <freeradius-devel/missing.h>
36#include <freeradius-devel/util/inet.h>
37#include <freeradius-devel/util/time.h>
52# define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
107#define FR_SOCKET_ADDR_ALLOC_DEF_FUNC(_func, ...) \
109 addr = talloc(ctx, fr_socket_t); \
110 if (unlikely(!addr)) return NULL; \
111 return _func(addr, ##__VA_ARGS__);
122 if (dst != src) *dst = tmp;
124 dst->inet.dst_ipaddr = tmp.inet.src_ipaddr;
125 dst->inet.dst_port = tmp.inet.src_port;
126 dst->inet.src_ipaddr = tmp.inet.dst_ipaddr;
127 dst->inet.src_port = tmp.inet.dst_port;
150 int ifindex,
fr_ipaddr_t const *src_ipaddr,
int src_port,
156 .
af = src_ipaddr->
af,
157 .type = (proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
160 .src_ipaddr = *src_ipaddr,
161 .src_port = src_port,
162 .dst_ipaddr = *dst_ipaddr,
189 int ifindex,
fr_ipaddr_t const *src_ipaddr,
int src_port,
193 proto, ifindex, src_ipaddr, src_port, dst_ipaddr, dst_port)
211 int proto,
int ifindex,
fr_ipaddr_t const *ipaddr,
int port)
217 .type = (proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
220 .src_ipaddr = *ipaddr,
263 .type = (proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
265 .dst_ipaddr = *ipaddr,
A time delta, a difference in time measured in nanoseconds.
static fr_socket_t * fr_socket_addr_alloc_inet_src(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_init_inet_src will also allocates a fr_socket_t.
int af
AF_INET, AF_INET6, or AF_UNIX.
int fd
File descriptor if this is a live socket.
int type
SOCK_STREAM, SOCK_DGRAM, etc.
static fr_socket_t * fr_socket_addr_init_inet(fr_socket_t *addr, int proto, int ifindex, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port)
Initialise a fr_socket_t for connecting to a remote host using a specific src interface,...
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_server_tcp(fr_ipaddr_t const *ipaddr, uint16_t *port, char const *port_name, bool async)
Open an IPv4/IPv6 TCP socket.
int fr_socket_server_udp(fr_ipaddr_t const *ipaddr, uint16_t *port, char const *port_name, bool async)
Open an IPv4/IPv6 unconnected UDP socket.
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.
static fr_socket_t * fr_socket_addr_alloc_inet_dst(TALLOC_CTX *ctx, int proto, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_alloc_inet_dst that will also allocates a fr_socket_t.
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.
static bool fr_socket_proto_is_known(int proto)
Check the proto value is sane/supported.
static fr_socket_t * fr_socket_addr_alloc_inet(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port)
Initialise a fr_socket_t for connecting to a remote host using a specific src interface,...
static fr_socket_t * fr_socket_addr_init_inet_src(fr_socket_t *addr, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_alloc_inet will also allocates a fr_socket_t.
int fr_socket_wait_for_connect(int sockfd, fr_time_delta_t timeout)
Wait for a socket to be connected, with an optional timeout.
#define FR_SOCKET_ADDR_ALLOC_DEF_FUNC(_func,...)
static fr_socket_t * fr_socket_addr_init_inet_dst(fr_socket_t *addr, int proto, fr_ipaddr_t const *ipaddr, int port)
Initialise a fr_socket_t for connecting to a remote host.
int fr_socket_client_unix(char const *path, bool async)
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Holds information necessary for binding or connecting to a socket.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.