summaryrefslogtreecommitdiff
path: root/nametoaddr.c
diff options
context:
space:
mode:
authorFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-07-14 11:07:24 +0200
committerFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-07-14 11:46:28 +0200
commit4802198948f237555c012070691cb7d16c9df08d (patch)
treeafbe50ed34680b51fbc265bae554a2a505db3c62 /nametoaddr.c
parent8cccd1dded942df5760eaf5b5d8faf1938a723f0 (diff)
downloadlibpcap-4802198948f237555c012070691cb7d16c9df08d.tar.gz
Update error codes for "real error" with getaddrinfo()
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).
Diffstat (limited to 'nametoaddr.c')
-rw-r--r--nametoaddr.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/nametoaddr.c b/nametoaddr.c
index 087d14be..194ff45b 100644
--- a/nametoaddr.c
+++ b/nametoaddr.c
@@ -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".