Set errno appropriately if we're building without IPv6 support and an IPv6 socket...
[freeradius.git] / src / lib / udpfromto.c
index 881941d..beda5cf 100644 (file)
@@ -98,7 +98,11 @@ int udpfromto_init(int s)
 
        errno = ENOSYS;
 
-#ifndef NDEBUG
+       /*
+        *      Clang analyzer doesn't see that getsockname initialises
+        *      the memory passed to it.
+        */
+#ifdef __clang_analyzer__
        memset(&si, 0, sizeof(si));
 #endif
 
@@ -114,7 +118,7 @@ int udpfromto_init(int s)
                proto = SOL_IP;
                flag = IP_PKTINFO;
 #else
-#ifdef IP_RECVDSTADDR
+#  ifdef IP_RECVDSTADDR
 
                /*
                 *      Set the IP_RECVDSTADDR option (BSD).  Note:
@@ -122,9 +126,9 @@ int udpfromto_init(int s)
                 */
                proto = IPPROTO_IP;
                flag = IP_RECVDSTADDR;
-#else
+#  else
                return -1;
-#endif
+#  endif
 #endif
 
 #ifdef AF_INET6
@@ -140,6 +144,9 @@ int udpfromto_init(int s)
                 */
                flag = FR_IPV6_RECVPKTINFO;
 #else
+#  ifdef EPROTONOSUPPORT
+               errno = EPROTONOSUPPORT;
+#  endif
                return -1;
 #  endif
 #endif
@@ -179,6 +186,14 @@ int recvfromto(int s, void *buf, size_t len, int flags,
        if (!to || !tolen) return recvfrom(s, buf, len, flags, from, fromlen);
 
        /*
+        *      Clang analyzer doesn't see that getsockname initialises
+        *      the memory passed to it.
+        */
+#ifdef __clang_analyzer__
+       memset(&si, 0, sizeof(si));
+#endif
+
+       /*
         *      recvmsg doesn't provide sin_port so we have to
         *      retrieve it using getsockname().
         */
@@ -452,7 +467,7 @@ int main(int argc, char **argv)
        struct sockaddr_in from, to, in;
        char buf[TESTLEN];
        char *destip = DESTIP;
-       int port = DEF_PORT;
+       uint16_t port = DEF_PORT;
        int n, server_socket, client_socket, fl, tl, pid;
 
        if (argc > 1) destip = argv[1];