]> The Tcpdump Group git mirrors - libpcap/commitdiff
Update error codes for "real error" with getaddrinfo()
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 14 Jul 2018 09:07:24 +0000 (11:07 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sat, 14 Jul 2018 09:46:28 +0000 (11:46 +0200)
For service translation, the EAI_NONAME check works on macOS, but not on
Debian Stretch.

The EAI_SERVICE check works on Debian Stretch.

Even if EAI_SERVICE, not EAI_NONAME, is supposed to be returned in that
case, The macOS require to check for both EAI_NONAME and EAI_SERVICE.

From Linux man page:
EAI_NONAME
       The  node  or service is not known; or both node and service are
       NULL; or AI_NUMERICSERV was specified in hints.ai_flags and ser-
       vice was not a numeric port-number string.

EAI_SERVICE
       The  requested service is not available for the requested socket
       type.  It may be available through  another  socket  type.   For
       example,  this  error could occur if service was "shell" (a ser-
       vice available only on stream sockets), and either hints.ai_pro-
       tocol  was  IPPROTO_UDP, or hints.ai_socktype was SOCK_DGRAM; or
       the  error  could  occur  if   service   was   not   NULL,   and
       hints.ai_socktype was SOCK_RAW (a socket type that does not sup-
       port the concept of services).

nametoaddr.c

index 087d14be750d663d9e2edc91e93790d5321b630e..194ff45b7588378b16d8eb4352687e1db4fa3768 100644 (file)
@@ -306,7 +306,8 @@ pcap_nametoport(const char *name, int *port, int *proto)
        hints.ai_protocol = IPPROTO_TCP;
        error = getaddrinfo(NULL, name, &hints, &res);
        if (error != 0) {
-               if (error != EAI_NONAME) {
+               if (error != EAI_NONAME &&
+                   error != EAI_SERVICE) {
                        /*
                         * This is a real error, not just "there's
                         * no such service name".
@@ -349,7 +350,8 @@ pcap_nametoport(const char *name, int *port, int *proto)
        hints.ai_protocol = IPPROTO_UDP;
        error = getaddrinfo(NULL, name, &hints, &res);
        if (error != 0) {
-               if (error != EAI_NONAME) {
+               if (error != EAI_NONAME &&
+                   error != EAI_SERVICE) {
                        /*
                         * This is a real error, not just "there's
                         * no such service name".