Blob Blame History Raw
diff -up apcupsd-3.14.13/src/apcaccess.c.netopenfix apcupsd-3.14.13/src/apcaccess.c
--- apcupsd-3.14.13/src/apcaccess.c.netopenfix	2015-11-23 13:03:18.960051659 +0100
+++ apcupsd-3.14.13/src/apcaccess.c	2015-11-23 13:07:37.225759158 +0100
@@ -49,7 +49,7 @@ static int do_pthreads_status(const char
    char recvline[MAXSTRING + 1];
    char *line;
 
-   if ((sockfd = net_open(host, NULL, port)) == INVALID_SOCKET) {
+   if ((sockfd = net_open(host, NULL, port)) < 0) {
       fprintf(stderr, "Error contacting apcupsd @ %s:%d: %s\n",
          host, port, strerror(-sockfd));
       return 1;
diff -up apcupsd-3.14.13/src/cgi/upsfetch.c.netopenfix apcupsd-3.14.13/src/cgi/upsfetch.c
--- apcupsd-3.14.13/src/cgi/upsfetch.c.netopenfix	2015-11-23 13:09:20.108837721 +0100
+++ apcupsd-3.14.13/src/cgi/upsfetch.c	2015-11-23 13:09:20.153838193 +0100
@@ -114,7 +114,7 @@ static int fetch_data(const char *host)
       *p++ = '\0';
       nis_port = atoi(p);
    }
-   if ((sockfd = net_open(lhost, NULL, nis_port)) == INVALID_SOCKET) {
+   if ((sockfd = net_open(lhost, NULL, nis_port)) < 0) {
       (void) snprintf(errmsg, sizeof (errmsg),
          "upsfetch: tcp_open failed for %s port %d", lhost, nis_port);
       return 0;
@@ -153,7 +153,7 @@ int fetch_events(const char *host)
       *p++ = '\0';
       nis_port = atoi(p);
    }
-   if ((sockfd = net_open(lhost, NULL, nis_port)) == INVALID_SOCKET) {
+   if ((sockfd = net_open(lhost, NULL, nis_port)) < 0) {
       snprintf(errmsg, sizeof(errmsg),
           "upsfetch: tcp_open failed for %s port %d", lhost, nis_port);
       fputs(errmsg, stdout);
diff -up apcupsd-3.14.13/src/drivers/net/net.c.netopenfix apcupsd-3.14.13/src/drivers/net/net.c
--- apcupsd-3.14.13/src/drivers/net/net.c.netopenfix	2015-11-23 13:09:33.997983325 +0100
+++ apcupsd-3.14.13/src/drivers/net/net.c	2015-11-23 13:09:34.041983787 +0100
@@ -202,7 +202,7 @@ bool NetUpsDriver::poll_ups()
    _statlen = 0;
 
    Dmsg(20, "Opening connection to %s:%d\n", _hostname, _port);
-   if ((_sockfd = net_open(_hostname, NULL, _port)) == INVALID_SOCKET) {
+   if ((_sockfd = net_open(_hostname, NULL, _port)) < 0) {
       Dmsg(90, "Exit poll_ups 0 comm lost\n");
       if (!_ups->is_commlost()) {
          _ups->set_commlost();
diff -up apcupsd-3.14.13/src/lib/statmgr.cpp.netopenfix apcupsd-3.14.13/src/lib/statmgr.cpp
--- apcupsd-3.14.13/src/lib/statmgr.cpp.netopenfix	2015-11-23 13:08:48.076501913 +0100
+++ apcupsd-3.14.13/src/lib/statmgr.cpp	2015-11-23 13:08:48.105502218 +0100
@@ -199,12 +199,12 @@ bool StatMgr::open()
       close();
 
    m_socket = net_open(m_host, NULL, m_port);
-   return m_socket != INVALID_SOCKET;
+   return m_socket >= 0;
 }
 
 void StatMgr::close()
 {
-   if (m_socket != INVALID_SOCKET) {
+   if (m_socket != INVALID_SOCKET && m_socket >= 0) {
       net_close(m_socket);
       m_socket = INVALID_SOCKET;
    }