* Open a socket TO the given IP and port.
*/
int fr_tcp_client_socket(fr_ipaddr_t *src_ipaddr,
- fr_ipaddr_t *dst_ipaddr, int dst_port)
+ fr_ipaddr_t *dst_ipaddr, uint16_t dst_port)
{
int sockfd;
struct sockaddr_storage salocal;
socklen_t salen;
- if ((dst_port < 0) || (dst_port > 65535)) {
- fr_strerror_printf("Port %d is out of allowed bounds",
- dst_port);
- return -1;
- }
-
if (!dst_ipaddr) return -1;
sockfd = socket(dst_ipaddr->af, SOCK_STREAM, 0);
return sockfd;
}
-#if 0
-#ifdef O_NONBLOCK
- {
- int flags;
-
- if ((flags = fcntl(sockfd, F_GETFL, NULL)) < 0) {
- fr_strerror_printf("Failure getting socket flags: %s",
- fr_syserror(errno));
- close(sockfd);
- return -1;
- }
-
- flags |= O_NONBLOCK;
- if( fcntl(sockfd, F_SETFL, flags) < 0) {
- fr_strerror_printf("Failure setting socket flags: %s",
- fr_syserror(errno));
- close(sockfd);
- return -1;
- }
- }
-#endif
-#endif
/*
* Allow the caller to bind us to a specific source IP.
*/
}
if (!fr_ipaddr2sockaddr(dst_ipaddr, dst_port, &salocal, &salen)) {
- close(sockfd);
+ close(sockfd);
return -1;
}
RADIUS_PACKET *fr_tcp_recv(int sockfd, int flags)
{
- RADIUS_PACKET *packet = rad_alloc(NULL, 0);
+ RADIUS_PACKET *packet = rad_alloc(NULL, false);
if (!packet) return NULL;
packet_len = (packet->vector[2] << 8) | packet->vector[3];
if (packet_len < AUTH_HDR_LEN) {
- fr_strerror_printf("Discarding packet: Smaller than RFC minimum of 20 bytes.");
+ fr_strerror_printf("Discarding packet: Smaller than RFC minimum of 20 bytes");
return -1;
}
* If the packet is too big, then the socket is bad.
*/
if (packet_len > MAX_PACKET_LEN) {
- fr_strerror_printf("Discarding packet: Larger than RFC limitation of 4096 bytes.");
+ fr_strerror_printf("Discarding packet: Larger than RFC limitation of 4096 bytes");
return -1;
}
/*
* See if it's a well-formed RADIUS packet.
*/
- if (!rad_packet_ok(packet, flags)) {
+ if (!rad_packet_ok(packet, flags, NULL)) {
return -1;
}
if (is_radius_code(packet->code)) {
- DEBUG("rad_recv: %s packet from %s",
+ DEBUG("Received %s packet from %s",
fr_packet_codes[packet->code], buffer);
} else {
- DEBUG("rad_recv: Packet from %s code=%d",
+ DEBUG("Received packet from %s code %d",
buffer, packet->code);
}
DEBUG(", id=%d, length=%zu\n", packet->id, packet->data_len);