diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-10-07 17:00:30 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-10-07 17:00:30 -0700 |
commit | 93d4983ccf8297c01829cd18b51ab46fba674477 (patch) | |
tree | a7c5a0a415f30517a725410e1aac3ade9634d394 | |
parent | 799d0bd20e34928200ba90a686e31cbfba80ea83 (diff) | |
download | libpcap-93d4983ccf8297c01829cd18b51ab46fba674477.tar.gz |
socket() and accept() return INVALID_SOCKET on errors.
On Windows, you're supposed to check against INVALID_SOCKET. On UN*X,
you're supposed to check against -1, but, on UN*X, we define
INVALID_SOCKET to be -1 so you can compare against INVALID_SOCKET on
both platforms.
That means that sock_open() should return INVALID_SOCKET on errors as
well.
-rw-r--r-- | pcap-rpcap.c | 6 | ||||
-rwxr-xr-x | rpcapd/daemon.c | 6 | ||||
-rwxr-xr-x | rpcapd/rpcapd.c | 6 | ||||
-rw-r--r-- | sockutils.c | 14 |
4 files changed, 16 insertions, 16 deletions
diff --git a/pcap-rpcap.c b/pcap-rpcap.c index d2dda54e..8ceb0b19 100644 --- a/pcap-rpcap.c +++ b/pcap-rpcap.c @@ -2210,7 +2210,7 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** return -1; } - if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { freeaddrinfo(addrinfo); return -1; @@ -2564,7 +2564,7 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * } - if ((sockmain = sock_open(addrinfo, SOCKOPEN_SERVER, 1, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockmain = sock_open(addrinfo, SOCKOPEN_SERVER, 1, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { SOCK_ASSERT(errbuf, 1); freeaddrinfo(addrinfo); @@ -2582,7 +2582,7 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * closesocket(sockmain); sockmain = 0; - if (sockctrl == -1) + if (sockctrl == INVALID_SOCKET) { sock_geterror("accept(): ", errbuf, PCAP_ERRBUF_SIZE); return -2; diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c index 5cd4355c..ac51ecac 100755 --- a/rpcapd/daemon.c +++ b/rpcapd/daemon.c @@ -1135,7 +1135,7 @@ static struct session *daemon_startcapture(SOCKET sockctrl, pthread_t *threaddat if (sock_initaddress(peerhost, portdata, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) goto error; - if ((sockdata = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockdata = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) goto error; } else // Data connection is opened by the client toward the server @@ -1146,7 +1146,7 @@ static struct session *daemon_startcapture(SOCKET sockctrl, pthread_t *threaddat if (sock_initaddress(NULL, "0", &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) goto error; - if ((sockdata = sock_open(addrinfo, SOCKOPEN_SERVER, 1 /* max 1 connection in queue */, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockdata = sock_open(addrinfo, SOCKOPEN_SERVER, 1 /* max 1 connection in queue */, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) goto error; // get the complete sockaddr structure used in the data connection @@ -1211,7 +1211,7 @@ static struct session *daemon_startcapture(SOCKET sockctrl, pthread_t *threaddat socktemp = accept(sockdata, (struct sockaddr *) &saddr, &saddrlen); - if (socktemp == -1) + if (socktemp == INVALID_SOCKET) { sock_geterror("accept(): ", errbuf, PCAP_ERRBUF_SIZE); goto error; diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index 81069b1d..1721c23f 100755 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -380,7 +380,7 @@ void main_startup(void) { SOCKET *socktemp; - if ((sockmain = sock_open(tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockmain = sock_open(tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { SOCK_ASSERT(errbuf, 1); tempaddrinfo = tempaddrinfo->ai_next; @@ -546,7 +546,7 @@ static void main_passive(void *ptr) sockctrl = accept(sockmain, (struct sockaddr *) &from, &fromlen); - if (sockctrl == -1) + if (sockctrl == INVALID_SOCKET) { // The accept() call can return this error when a signal is catched // In this case, we have simply to ignore this error code @@ -684,7 +684,7 @@ static void main_active(void *ptr) { int activeclose; - if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == -1) + if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { SOCK_ASSERT(errbuf, 1); diff --git a/sockutils.c b/sockutils.c index dba739dc..d5b53eb8 100644 --- a/sockutils.c +++ b/sockutils.c @@ -279,7 +279,7 @@ static int sock_ismcastaddr(const struct sockaddr *saddr) * larger than 'errbuflen - 1' because the last char is reserved for the string terminator. * * \return the socket that has been opened (that has to be used in the following sockets calls) - * if everything is fine, '0' if some errors occurred. The error message is returned + * if everything is fine, INVALID_SOCKET if some errors occurred. The error message is returned * in the 'errbuf' variable. */ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, int errbuflen) @@ -287,10 +287,10 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, SOCKET sock; sock = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol); - if (sock == -1) + if (sock == INVALID_SOCKET) { sock_geterror("socket(): ", errbuf, errbuflen); - return -1; + return INVALID_SOCKET; } @@ -313,7 +313,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, if (errbuf) pcap_snprintf(errbuf, errbuflen, "setsockopt(IPV6_BINDV6ONLY)"); closesocket(sock); - return -1; + return INVALID_SOCKET; } } #endif @@ -323,7 +323,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, { sock_geterror("bind(): ", errbuf, errbuflen); closesocket(sock); - return -1; + return INVALID_SOCKET; } if (addrinfo->ai_socktype == SOCK_STREAM) @@ -331,7 +331,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, { sock_geterror("listen(): ", errbuf, errbuflen); closesocket(sock); - return -1; + return INVALID_SOCKET; } /* server side ended */ @@ -396,7 +396,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, if (tempaddrinfo == NULL) { closesocket(sock); - return -1; + return INVALID_SOCKET; } else return sock; |