From 3579f8840d48f7cabc303d480673d5de72b3c757 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 6 Feb 2017 16:12:21 -0600 Subject: [PATCH] getservbyport_r: return ENOENT if service not found getnameinfo will return the numeric form of the service if it has no name. This is conformant behaviour for getnameinfo, but not for getservbyport{,_r}. NFS for Linux and some BitTorrent clients use getservbyport(3) to check if a port has an IANA reservation before using it for port mapping. With the present behaviour, these packages (and assumedly others) fail to ever find a free port, and refuse to start (or in the case of NFS, simply refuse any connections). This patch solves the conformance issue for getservbyport *and* getservbyport_r (since the first calls in to the second in musl). Signed-off-by: A. Wilcox --- src/network/getservbyport_r.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/getservbyport_r.c b/src/network/getservbyport_r.c index a0a7cae..37a001b 100644 --- a/src/network/getservbyport_r.c +++ b/src/network/getservbyport_r.c @@ -5,6 +5,7 @@ #include #include #include +#include int getservbyport_r(int port, const char *prots, struct servent *se, char *buf, size_t buflen, struct servent **res) @@ -50,6 +51,7 @@ int getservbyport_r(int port, const char *prots, break; } + if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT; *res = se; return 0; } -- 2.10.0