23 RCSID(
"$Id: 3b2c4721a1220faba30ce296edbab23acdb3eeda $")
25 #include <freeradius-devel/util/log.h>
26 #include <freeradius-devel/util/socket.h>
27 #include <freeradius-devel/util/strerror.h>
28 #include <freeradius-devel/util/syserror.h>
29 #include <freeradius-devel/util/udp.h>
31 #define FR_DEBUG_STRERROR_PRINTF if (fr_debug_lvl) fr_strerror_printf
50 ret = (send(sock->
fd,
data, data_len, 0) == (
ssize_t)data_len) ? 0 : -1;
52 struct sockaddr_storage dst, src;
53 socklen_t sizeof_dst, sizeof_src;
56 &sock->inet.dst_ipaddr, sock->inet.dst_port) < 0)
return -1;
58 &sock->inet.src_ipaddr, sock->inet.src_port) < 0)
return -1;
62 (
struct sockaddr *)&src, sizeof_src,
63 (
struct sockaddr *)&dst, sizeof_dst);
79 struct sockaddr_storage src;
80 socklen_t sizeof_src =
sizeof(src);
83 (
struct sockaddr *)&src, &sizeof_src);
99 struct sockaddr_storage src;
100 socklen_t sizeof_src =
sizeof(src);
103 peeked = recv(
sockfd,
data, data_len, MSG_PEEK);
105 if ((errno == EAGAIN) || (errno == EINTR))
return 0;
112 peeked = recvfrom(
sockfd,
data, data_len, MSG_PEEK, (
struct sockaddr *)&src, &sizeof_src);
114 if ((errno == EAGAIN) || (errno == EINTR))
return 0;
149 struct sockaddr_storage src;
150 struct sockaddr_storage dst;
151 socklen_t sizeof_src =
sizeof(src);
152 socklen_t sizeof_dst =
sizeof(dst);
171 slen = recv(
sockfd,
data, data_len, sock_flags);
180 &socket_out->inet.ifindex,
181 (
struct sockaddr *)&src, &sizeof_src,
182 (
struct sockaddr *)&dst, &sizeof_dst,
184 if (slen <= 0)
goto done;
197 if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
return 0;
int fr_ipaddr_from_sockaddr(fr_ipaddr_t *ipaddr, uint16_t *port, struct sockaddr_storage const *sa, socklen_t salen)
Convert sockaddr to our internal ip address representation.
int fr_ipaddr_to_sockaddr(struct sockaddr_storage *sa, socklen_t *salen, fr_ipaddr_t const *ipaddr, uint16_t port)
Convert our internal ip address representation to a sockaddr.
int udp_recv_discard(int sockfd)
Discard the next UDP packet.
ssize_t udp_recv_peek(int sockfd, void *data, size_t data_len, int flags, fr_ipaddr_t *src_ipaddr, uint16_t *src_port)
Peek at the header of a UDP packet.
ssize_t udp_recv(int sockfd, int flags, fr_socket_t *socket_out, void *data, size_t data_len, fr_time_t *when)
Read a UDP packet.
#define FR_DEBUG_STRERROR_PRINTF
int udp_send(fr_socket_t const *sock, int flags, void *data, size_t data_len)
Send a packet via a UDP socket.
#define fr_time()
Allow us to arbitrarily manipulate time.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_time_wrap(_time)
#define fr_time_eq(_a, _b)
#define UDP_FLAGS_CONNECTED
int sendfromto(int fd, void *buf, size_t len, int flags, int ifindex, struct sockaddr *from, socklen_t from_len, struct sockaddr *to, socklen_t to_len)
Send packet via a file descriptor, setting the src address and outbound interface.
int recvfromto(int fd, void *buf, size_t len, int flags, int *ifindex, struct sockaddr *from, socklen_t *from_len, struct sockaddr *to, socklen_t *to_len, fr_time_t *when)
Read a packet from a file descriptor, retrieving additional header information.
int fd
File descriptor if this is a live socket.
int type
SOCK_STREAM, SOCK_DGRAM, etc.
Holds information necessary for binding or connecting to a socket.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const_push(_msg)