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).
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".
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".