The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
udpfromto.c File Reference

API for sending and receiving packets on unconnected UDP sockets. More...

#include <freeradius-devel/util/udpfromto.h>
#include <fcntl.h>
+ Include dependency graph for udpfromto.c:

Go to the source code of this file.

Macros

#define SOL_IP   IPPROTO_IP
 

Functions

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. More...
 
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. More...
 
int udpfromto_init (int s, int af)
 

Detailed Description

API for sending and receiving packets on unconnected UDP sockets.

Like recvfrom, but also stores the destination IP address. Useful on multihomed hosts.

Definition in file udpfromto.c.

Macro Definition Documentation

◆ SOL_IP

#define SOL_IP   IPPROTO_IP

Definition at line 41 of file udpfromto.c.

Function Documentation

◆ recvfromto()

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.

Abstracts away the complexity of using the complexity of using recvmsg().

In addition to reading data from the file descriptor, the src and dst addresses and the receiving interface index are retrieved. This enables us to send replies using the correct IP interface, in the case where the server is multihomed. This is not normally possible on unconnected datagram sockets.

Parameters
[in]fdThe file descriptor to read from.
[out]bufWhere to write the received datagram data.
[in]lenof buf.
[in]flagspassed unmolested to recvmsg.
[out]ifindexThe interface which received the datagram (may be NULL). Will only be populated if to is not NULL.
[out]fromWhere to write the source address.
[in]from_lenLength of the structure pointed to by from.
[out]toWhere to write the destination address. If NULL recvmsg() will be used instead.
[in]to_lenLength of the structure pointed to by to.
[out]whenthe packet was received (may be NULL). If SO_TIMESTAMP is not available or SO_TIMESTAMP Was not set on the socket, then another method will be used instead to get the time.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 191 of file udpfromto.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendfromto()

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.

Abstracts away the complexity of using the complexity of using sendmsg().

Parameters
[in]fdThe file descriptor to write to.
[in]bufWhere to read datagram data from.
[in]lenof datagram data.
[in]flagspassed unmolested to sendmsg.
[in]ifindexThe interface on which to send the datagram. If automatic interface selection is desired, value should be 0.
[in]fromThe source address.
[in]from_lenLength of the structure pointed to by from.
[in]toThe destination address.
[in]to_lenLength of the structure pointed to by to.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 391 of file udpfromto.c.

+ Here is the caller graph for this function:

◆ udpfromto_init()

int udpfromto_init ( int  s,
int  af 
)

Definition at line 92 of file udpfromto.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: