28RCSIDH(socket_h,
"$Id: 6a6460f79064afa6d29cc8c117a24a719ab3b6a7 $")
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>
55# define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
110#define FR_SOCKET_ADDR_ALLOC_DEF_FUNC(_func, ...) \
112 addr = talloc(ctx, fr_socket_t); \
113 if (unlikely(!addr)) return NULL; \
114 return _func(addr, ##__VA_ARGS__);
125 if (dst != src) *dst = tmp;
127 dst->inet.dst_ipaddr = tmp.inet.src_ipaddr;
128 dst->inet.dst_port = tmp.inet.src_port;
129 dst->inet.src_ipaddr = tmp.inet.dst_ipaddr;
130 dst->inet.src_port = tmp.inet.dst_port;
153 int ifindex,
fr_ipaddr_t const *src_ipaddr,
int src_port,
159 .
af = src_ipaddr->
af,
160 .type = (
proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
163 .src_ipaddr = *src_ipaddr,
164 .src_port = src_port,
165 .dst_ipaddr = *dst_ipaddr,
192 int ifindex,
fr_ipaddr_t const *src_ipaddr,
int src_port,
196 proto, ifindex, src_ipaddr, src_port, dst_ipaddr, dst_port)
220 .type = (
proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
223 .src_ipaddr = *ipaddr,
266 .type = (
proto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM,
268 .dst_ipaddr = *ipaddr,
static char const * proto(int id, int porttype)
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.