- if (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
- strcmp(prots, "udp") ? 0 : NI_DGRAM) < 0) return -1;
+ switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
+ strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
+ case EAI_MEMORY:
+ case EAI_SYSTEM:
+ return ENOMEM;
+ default:
+ return ENOENT;
+ case 0:
+ break;
+ }
+
+ /* A numeric port string is not a service record. */
+ if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;