summaryrefslogtreecommitdiff
path: root/pcap-rpcap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-07-31 11:30:43 -0700
committerGuy Harris <gharris@sonic.net>2022-08-01 02:13:36 -0700
commit33cf6fb70a13a982d70f6a5e5e63aa765073c8e8 (patch)
tree1dc1d9c114ff336d3889318d340dad5701ab728a /pcap-rpcap.c
parente2cc98d5e3a4ecee5b59f80827b76f06d4e88be7 (diff)
downloadlibpcap-33cf6fb70a13a982d70f6a5e5e63aa765073c8e8.tar.gz
rpcap: improve error messages for host and port resolution errors.
If we don't want a particular port nuber in a sock_initaddress() call, pass NULL rather than "0". If the service name parameter passsed to sock_initaddress() is NULL, pass "0" as the service name parameter to getaddrinfo(). Have get_gai_errstring() precede the host/port name information with an indication as to whethe it's a host name, port name, or host name and port name. Don't say "host name" for EAI_NONAME; rely on the description get_gai_errstring() provides. If there's only a port number, don't preceded it with ":" in get_gai_errstring(). This makes the error message reported if a host and port are provided not say that the host name couldn't be resolved, because it could be a problem with the port name (sadly, getaddinfo() doesn't indicate which is the one with the problem). It also makes the error message reported if only a port is provided not say that it's a problem with the host name or show the "host name" as ":<port>".
Diffstat (limited to 'pcap-rpcap.c')
-rw-r--r--pcap-rpcap.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/pcap-rpcap.c b/pcap-rpcap.c
index 6b1a1d1a..5978de80 100644
--- a/pcap-rpcap.c
+++ b/pcap-rpcap.c
@@ -1020,7 +1020,7 @@ rpcap_remoteact_getsock(const char *host, int *error, char *errbuf)
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
- retval = sock_initaddress(host, "0", &hints, &addrinfo, errbuf,
+ retval = sock_initaddress(host, NULL, &hints, &addrinfo, errbuf,
PCAP_ERRBUF_SIZE);
if (retval != 0)
{
@@ -1172,7 +1172,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
hints.ai_flags = AI_PASSIVE; /* Data connection is opened by the server toward the client */
/* Let's the server pick up a free network port for us */
- if (sock_initaddress(NULL, "0", &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
+ if (sock_initaddress(NULL, NULL, &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
goto error_nodiscard;
if ((sockdata = sock_open(addrinfo, SOCKOPEN_SERVER,
@@ -3110,7 +3110,7 @@ int pcap_remoteact_close(const char *host, char *errbuf)
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
- retval = sock_initaddress(host, "0", &hints, &addrinfo, errbuf,
+ retval = sock_initaddress(host, NULL, &hints, &addrinfo, errbuf,
PCAP_ERRBUF_SIZE);
if (retval != 0)
{