Portability fixes for Mingw33
[freeradius.git] / src / main / listen.c
index bd66829..dd87af6 100644 (file)
@@ -561,9 +561,11 @@ static int dual_tcp_accept(rad_listen_t *listener)
                /*
                 *      Non-blocking sockets must handle this.
                 */
+#ifdef EWOULDBLOCK
                if (errno == EWOULDBLOCK) {
                        return 0;
                }
+#endif
 
                DEBUG2(" ... failed to accept connection.");
                return -1;
@@ -854,6 +856,7 @@ static int common_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
        /*
         *      Try IPv4 first
         */
+       memset(&ipaddr, 0, sizeof(ipaddr));
        ipaddr.ipaddr.ip4addr.s_addr = htonl(INADDR_NONE);
        rcode = cf_item_parse(cs, "ipaddr", PW_TYPE_IPADDR,
                              &ipaddr.ipaddr.ip4addr, NULL);
@@ -1205,7 +1208,7 @@ static int proxy_socket_send(rad_listen_t *listener, REQUEST *request)
        rad_assert(request->proxy_listener == listener);
        rad_assert(listener->send == proxy_socket_send);
 
-       if (rad_send(request->proxy, request->packet,
+       if (rad_send(request->proxy, NULL,
                     request->home_server->secret) < 0) {
                radlog_request(L_ERR, 0, request, "Failed sending proxied request: %s",
                               fr_strerror());
@@ -2039,6 +2042,14 @@ static int listen_bind(rad_listen_t *this)
        }
 
        /*
+        *      Don't open sockets if we're checking the config.
+        */
+       if (check_config) {
+               this->fd = -1;
+               return 0;
+       }
+
+       /*
         *      Copy fr_socket() here, as we may need to bind to a device.
         */
        this->fd = socket(sock->my_ipaddr.af, sock_type, 0);
@@ -2057,7 +2068,9 @@ static int listen_bind(rad_listen_t *this)
        if (sock->interface) {
 #ifdef SO_BINDTODEVICE
                struct ifreq ifreq;
-               strcpy(ifreq.ifr_name, sock->interface);
+
+               memset(&ifreq, 0, sizeof(ifreq));
+               strlcpy(ifreq.ifr_name, sock->interface, sizeof(ifreq.ifr_name));
 
                fr_suid_up();
                rcode = setsockopt(this->fd, SOL_SOCKET, SO_BINDTODEVICE,
@@ -2852,7 +2865,7 @@ add_sockets:
                        return -1;
                }
 #endif
-               event_new_fd(this);
+               if (!check_config) event_new_fd(this);
        }
 
        /*
@@ -2861,6 +2874,7 @@ add_sockets:
         */
 #ifdef WITH_PROXY
        if ((mainconfig.proxy_requests == TRUE) &&
+           !check_config &&
            (*head != NULL) && !defined_proxy) {
                listen_socket_t *sock = NULL;
                int             port = 0;