fix logic error for skipping failed interfaces in if_nameindex
[musl] / src / network / getservbyport_r.c
index 004a616..821afae 100644 (file)
@@ -15,6 +15,10 @@ int getservbyport_r(int port, const char *prots,
                .sin_port = port,
        };
 
+       if (!prots) return -(
+               getservbyport_r(port, "tcp", se, buf, buflen, res)
+               && getservbyport_r(port, "udp", se, buf, buflen, res) );
+
        /* Align buffer */
        i = (uintptr_t)buf & sizeof(char *)-1;
        if (!i) i = sizeof(char *);
@@ -35,7 +39,7 @@ int getservbyport_r(int port, const char *prots,
        se->s_aliases[1] = 0;
        se->s_aliases[0] = se->s_name = buf;
 
-       if (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen, 
+       if (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
                strcmp(prots, "udp") ? 0 : NI_DGRAM) < 0) return -1;
 
        *res = se;