noip.c: Make the `unix_socket_status' return a bitfield.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 9 Jun 2018 14:51:07 +0000 (15:51 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 9 Jun 2018 14:58:23 +0000 (15:58 +0100)
The constant names are the same, but they're processed differently.

noip.c

diff --git a/noip.c b/noip.c
index 0063ee9..68b4978 100644 (file)
--- a/noip.c
+++ b/noip.c
 
 /*----- Data structures ---------------------------------------------------*/
 
-enum { UNUSED, STALE, USED };          /* Unix socket status values */
+/* Unix socket status values. */
+#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 */
+
 enum { DENY, ALLOW };                  /* ACL verdicts */
 
 static int address_families[] = { AF_INET, AF_INET6, -1 };
@@ -749,7 +753,7 @@ static int encode_unused_inet_addr(struct sockaddr *sa,
    * desperate.  If the socket is in use, we fail here.  (This could get
    * racy.  Let's not worry about that for now.)
    */
-  if (encode_single_inet_addr(sa, sun, !desperatep) == USED)
+  if (encode_single_inet_addr(sa, sun, !desperatep)&USED)
     return (-1);
 
   /* Next, check the corresponding wildcard address, so as to avoid
@@ -757,7 +761,7 @@ static int encode_unused_inet_addr(struct sockaddr *sa,
    */
   wildcard_address(sa->sa_family, &waddr.sa);
   port_to_sockaddr(&waddr.sa, port);
-  if (encode_single_inet_addr(&waddr.sa, &wsun, !desperatep) == USED)
+  if (encode_single_inet_addr(&waddr.sa, &wsun, !desperatep)&USED)
     return (-1);
 
   /* We're not done yet.  If this is an IPv4 address, then /also/ check (a)
@@ -766,16 +770,16 @@ static int encode_unused_inet_addr(struct sockaddr *sa,
    */
   if (sa->sa_family == AF_INET) {
     map_ipv4_sockaddr(&maddr.sin6, SIN(&sa));
-    if (encode_single_inet_addr(&maddr.sa, &wsun, !desperatep) == USED)
+    if (encode_single_inet_addr(&maddr.sa, &wsun, !desperatep)&USED)
       return (-1);
 
     map_ipv4_sockaddr(&maddr.sin6, &waddr.sin);
-    if (encode_single_inet_addr(&maddr.sa, &wsun, !desperatep) == USED)
+    if (encode_single_inet_addr(&maddr.sa, &wsun, !desperatep)&USED)
       return (-1);
 
     wildcard_address(AF_INET6, &waddr.sa);
     port_to_sockaddr(&waddr.sa, port);
-    if (encode_single_inet_addr(&waddr.sa, &wsun, !desperatep) == USED)
+    if (encode_single_inet_addr(&waddr.sa, &wsun, !desperatep)&USED)
       return (-1);
   }
 
@@ -799,6 +803,7 @@ static int encode_inet_addr(struct sockaddr_un *sun,
   address addr;
   struct sockaddr_in6 sin6;
   int port = port_from_sockaddr(sa);
+  int rc;
   char buf[ADDRBUFSZ];
 
   D( fprintf(stderr, "noip(%d): encode %s (%s)", getpid(),
@@ -813,8 +818,8 @@ static int encode_inet_addr(struct sockaddr_un *sun,
     /* Try the address as given.  If it's in use, or we don't necessarily
      * want an existing socket, then we're done.
      */
-    if (encode_single_inet_addr(sa, sun, 0) == USED || (f&ENCF_FRESH))
-      goto found;
+    rc = encode_single_inet_addr(sa, sun, 0);
+    if ((rc&USED) || (f&ENCF_FRESH)) goto found;
 
     /* We're looking for a socket which already exists.  This is
      * unfortunately difficult, because we must deal both with wildcards and
@@ -836,19 +841,19 @@ static int encode_inet_addr(struct sockaddr_un *sun,
 
     if (sa->sa_family == AF_INET) {
       map_ipv4_sockaddr(&addr.sin6, SIN(sa));
-      if (encode_single_inet_addr(&addr.sa, sun, 0) == USED) goto found;
+      if (encode_single_inet_addr(&addr.sa, sun, 0)&USED) goto found;
     }
 
     wildcard_address(sa->sa_family, &addr.sa);
     port_to_sockaddr(&addr.sa, port);
-    if (encode_single_inet_addr(&addr.sa, sun, 0) == USED) goto found;
+    if (encode_single_inet_addr(&addr.sa, sun, 0)&USED) goto found;
 
     if (sa->sa_family == AF_INET) {
       map_ipv4_sockaddr(&sin6, &addr.sin);
-      if (encode_single_inet_addr(SA(&sin6), sun, 0) == USED) goto found;
+      if (encode_single_inet_addr(SA(&sin6), sun, 0)&USED) goto found;
       wildcard_address(AF_INET6, &addr.sa);
       port_to_sockaddr(&addr.sa, port);
-      if (encode_single_inet_addr(&addr.sa, sun, 0) == USED) goto found;
+      if (encode_single_inet_addr(&addr.sa, sun, 0)&USED) goto found;
     }
 
     /* Well, this isn't going to work (unless a miraculous race is lost), but