dns: implement tcp fallback in __res_msend query core
[musl] / src / network / getservbyname_r.c
index 056c2f3..cad6317 100644 (file)
@@ -5,6 +5,7 @@
 #include <inttypes.h>
 #include <errno.h>
 #include <string.h>
+#include <stdlib.h>
 #include "lookup.h"
 
 #define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
@@ -15,6 +16,13 @@ int getservbyname_r(const char *name, const char *prots,
        struct service servs[MAXSERVS];
        int cnt, proto, align;
 
+       *res = 0;
+
+       /* Don't treat numeric port number strings as service records. */
+       char *end = "";
+       strtoul(name, &end, 10);
+       if (!*end) return ENOENT;
+
        /* Align buffer */
        align = -(uintptr_t)buf & ALIGN-1;
        if (buflen < 2*sizeof(char *)+align)