noip.c (unix_socket_status): Return whether anyone's listening.
[preload-hacks] / noip.c
diff --git a/noip.c b/noip.c
index 9dfc6c3..45ed9a5 100644 (file)
--- a/noip.c
+++ b/noip.c
@@ -63,6 +63,7 @@
 #define UNUSED 0u                      /* No sign of anyone using it */
 #define STALE 1u                       /* Socket exists, but is abandoned */
 #define USED 16u                       /* Socket is in active use */
+#define LISTEN 2u                      /* Socket has an active listener */
 
 enum { DENY, ALLOW };                  /* ACL verdicts */
 
@@ -680,6 +681,7 @@ static int unix_socket_status(struct sockaddr_un *sun, int quickp)
   FILE *fp = 0;
   size_t len, n;
   int rc;
+  unsigned long f;
   char buf[256];
 
   /* If we can't find the socket node, then it's definitely not in use.  If
@@ -710,6 +712,8 @@ static int unix_socket_status(struct sockaddr_un *sun, int quickp)
     if (n >= len + 2 && buf[n - len - 2] == ' ' && buf[n - 1] == '\n' &&
        memcmp(buf + n - len - 1, sun->sun_path, len) == 0) {
       rc |= USED;
+      if (sscanf(buf, "%*s %*x %*x %lx", &f) < 0 || (f&0x00010000))
+       rc |= LISTEN;
     }
   }
   if (ferror(fp))
@@ -734,9 +738,9 @@ static int encode_single_inet_addr(const struct sockaddr *sa,
 
   snprintf(sun->sun_path, sizeof(sun->sun_path), "%s/%s", sockdir,
           present_sockaddr(sa, 0, buf, sizeof(buf)));
-  if ((rc = unix_socket_status(sun, quickp)) == USED) return (USED);
-  else if (rc == STALE) unlink(sun->sun_path);
-  return (UNUSED);
+  rc = unix_socket_status(sun, quickp);
+  if (rc == STALE) unlink(sun->sun_path);
+  return (rc);
 }
 
 /* Convert the IP address SA to a Unix-domain address SUN.  Fail if the