newvector should be a bool
[freeradius.git] / src / lib / tcp.c
index a2c5331..186198c 100644 (file)
@@ -33,18 +33,12 @@ RCSID("$Id$")
  *     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);
@@ -52,28 +46,6 @@ int fr_tcp_client_socket(fr_ipaddr_t *src_ipaddr,
                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.
         */
@@ -92,7 +64,7 @@ int fr_tcp_client_socket(fr_ipaddr_t *src_ipaddr,
        }
 
        if (!fr_ipaddr2sockaddr(dst_ipaddr, dst_port, &salocal, &salen)) {
-                       close(sockfd);
+               close(sockfd);
                return -1;
        }
 
@@ -113,7 +85,7 @@ int fr_tcp_client_socket(fr_ipaddr_t *src_ipaddr,
 
 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;
 
@@ -176,7 +148,7 @@ int fr_tcp_read_packet(RADIUS_PACKET *packet, int flags)
                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;
                }
 
@@ -184,7 +156,7 @@ int fr_tcp_read_packet(RADIUS_PACKET *packet, int flags)
                 *      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;
                }
 
@@ -226,7 +198,7 @@ int fr_tcp_read_packet(RADIUS_PACKET *packet, int flags)
        /*
         *      See if it's a well-formed RADIUS packet.
         */
-       if (!rad_packet_ok(packet, flags)) {
+       if (!rad_packet_ok(packet, flags, NULL)) {
                return -1;
        }
 
@@ -251,10 +223,10 @@ int fr_tcp_read_packet(RADIUS_PACKET *packet, int flags)
 
 
                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);