networkclient
|
Functions | |
ssize_t | nr_socket_recv (RADIUS_PACKET *packet) |
int | nr_socket_send (RADIUS_PACKET *packet) |
ssize_t | nr_socket_recv_response (RADIUS_PACKET *response, const RADIUS_PACKET *request) |
int | nr_socket_send_response (RADIUS_PACKET *packet, const RADIUS_PACKET *original) |
struct sockaddr_storage * | nr_ipv42sockaddr (uint32_t ipaddr, int port, struct sockaddr_storage *s) |
int | sockaddr_cmp (const struct sockaddr_storage *a, const struct sockaddr_storage *b) |
int | nr_socket_open (struct sockaddr_storage *s) |
int | nr_track_id_socket (nr_track_id_t *s, struct sockaddr_storage *src, struct sockaddr_storage *dst) |
These routines send / receive packets, and do other socket-related functions. These routines are not part of the BSD licensed RADIUS library.
struct sockaddr_storage* nr_ipv42sockaddr | ( | uint32_t | ipaddr, |
int | port, | ||
struct sockaddr_storage * | s | ||
) |
Converts an IP address and port into a sockaddr structure..
[in] | ipaddr | The IPv4 address to use. |
[in] | port | The port to use |
[out] | s | The initialized sockaddr_storage structure. |
Referenced by main(), and nr_socket_open().
int nr_socket_open | ( | struct sockaddr_storage * | s | ) |
Create a socket using the given IP information.
IPv4 sockets can easily be created by calling nr_socket_open(nr_ipv42sockaddr(ip, port, sockaddr_storage));
The parameter 's' can be NULL, in which case it binds to IPv4 0.0.0.0, port 0. Since 's' is NULL, the function cannot return the IP and port to which the socket was bound.
The file descriptor returned can be released with a call to close().
[in,out] | s | The structure where the socket information is stored. |
References nr_ipv42sockaddr(), nr_strerror_printf(), return_NR_ERR, and UNUSED.
Referenced by main(), and nr_track_id_socket().
ssize_t nr_socket_recv | ( | RADIUS_PACKET * | packet | ) |
Receives a response to a request.
This function reads a packet from the RADIUS_PACKET::sockfd, by calling recv().
Only valid RADIUS packets are returned from this function.
When data is read from a socket, that data might not be a valid RADIUS packet. This function ensures that the all non-RADIUS data is ignored and discarded from the socket.
When a valid packet is read, the function returns the total number of bytes received (>0).
Many of the fields of the RADIUS_PACKET structure are filled in with the relevant data from the "raw" packet. (e.g. RADIUS_PACKET::code, RADIUS_PACKET::id, RADIUS_PACKET::length, RADIUS_PACKET::vector, and RADIUS_PACKET::src)
This function is blocking. You will need to ensure that data is ready before calling it, otherwise it will block until there is data available on the socket.
The "raw" packet data is written to RADIUS_PACKET::data, up to RADIUS_PACKET::length. If RADIUS_PACKET::data is NULL, then the memory is allocated.
[in] | packet | The RADIUS packet to receive |
References radius_packet::code, radius_packet::data, radius_packet::id, radius_packet::length, nr_debug_error, NR_MAX_PACKET_LEN, nr_packet_ok(), return_NR_ERR, radius_packet::sizeof_addr, radius_packet::sizeof_data, radius_packet::sockfd, radius_packet::src, radius_packet::vector, and radius_packet::vps.
Referenced by nr_socket_recv_response().
ssize_t nr_socket_recv_response | ( | RADIUS_PACKET * | response, |
const RADIUS_PACKET * | request | ||
) |
Receives a response to a request.
This function reads a packet from the RADIUS_PACKET::sockfd, using nr_socket_recv(). The return value is the same as nr_socket_recv().
This function should be used when there is only one request being sent on a particular socket. In that case, the only possible data to receive on that socket is a valid response to the request.
The response packet is verified, and decoded.
[in] | response | The RADIUS packet to receive |
[in] | request | The original request |
References radius_packet::length, nr_packet_decode(), nr_packet_response_ok(), nr_packet_verify(), nr_socket_recv(), return_NR_ERR, radius_packet::sockfd, and radius_packet::timestamp.
Referenced by main().
int nr_socket_send | ( | RADIUS_PACKET * | packet | ) |
Sends a packet.
This function sends a packet using the RADIUS_PACKET::sockfd field. Request packets are automatically encoded and signed, if necessary. Response packets must be already signed via nr_packet_sign(), otherwise NR_ERR_PACKET_UNSIGNED is returned.
[in] | packet | The RADIUS packet to send |
References radius_packet::attempts, radius_packet::data, radius_packet::dst, radius_packet::flags, radius_packet::length, nr_debug_error, nr_packet_can_encode(), nr_packet_sign(), NR_PACKET_SIGNED, return_NR_ERR, radius_packet::sizeof_addr, radius_packet::sockfd, and radius_packet::timestamp.
Referenced by main(), and nr_socket_send_response().
int nr_socket_send_response | ( | RADIUS_PACKET * | packet, |
const RADIUS_PACKET * | original | ||
) |
Sends a response to a request.
If RADIUS_PACKET::encoded is 0, then nr_packet_encode() is called to encode the packet. Otherwise, it assumes that nr_packet_encode() has already been called, and that the RADIUS_PACKET::data and RADIUS_PACKET::length fields are valid. See nr_packet_encode() for other requirements on the fields of the RADIUS_PACKET structure.
When a valid packet is sent, the function returns the total number of bytes sent (>0), even if RADIUS_PACKET::data is NULL.
[in] | packet | The RADIUS packet to encode |
[in] | original | The original request |
References nr_packet_ok(), nr_packet_sign(), nr_socket_send(), and return_NR_ERR.
int nr_track_id_socket | ( | nr_track_id_t * | s, |
struct sockaddr_storage * | src, | ||
struct sockaddr_storage * | dst | ||
) |
Set a nr_track_id_t to a src/dst address/port
This function intializes nr_track_id_t::sockfd, nr_track_id_t::src, and nr_track_id_t::dst.
[in,out] | s | The server structure to initialize |
[in] | src | Source address and port |
[in] | dst | Destination address and port |
References nr_track_id_t::ctx, nr_track_id_t::dst, nr_socket_open(), nr_track_id_t::packet_send, return_NR_ERR, nr_track_id_t::secret, nr_track_id_t::sizeof_secret, nr_track_id_t::sockfd, and nr_track_id_t::src.
Referenced by main().
int sockaddr_cmp | ( | const struct sockaddr_storage * | a, |
const struct sockaddr_storage * | b | ||
) |
Compares two sockaddrs..
[in] | a | One sockaddr_storage |
[in] | b | Another one |