linux.c: Implement the return-code protocol described.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 18 Jan 2015 04:07:44 +0000 (04:07 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 18 Jan 2015 04:13:35 +0000 (04:13 +0000)
It should return zero on success or -1 on failure, because it's an
operation which attempts to return a value, and so might fail -- as
opposed to a predicate asking a simple boolean question about the world.

No actual harm done, because the code was correct to begin with, but
potentially confusing later.

linux.c

diff --git a/linux.c b/linux.c
index 2c9a1d7..17a27a8 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -97,7 +97,7 @@ static int get_default_gw(int af, union addr *a)
   const struct rtattr *rta;
   const struct rtmsg *rtm;
   ssize_t n, nn;
-  int rc = 0;
+  int rc = -1;
   static unsigned long seq = 0x48b4aec4;
 
   /* Open a netlink socket for interrogating the kernel. */
@@ -163,7 +163,7 @@ static int get_default_gw(int af, union addr *a)
        if (rta->rta_type == RTA_GATEWAY) {
          assert(RTA_PAYLOAD(rta) <= sizeof(*a));
          memcpy(a, RTA_DATA(rta), RTA_PAYLOAD(rta));
-         rc = 1;
+         rc = 0;
        }
       }
     }
@@ -201,7 +201,7 @@ void identify(struct query *q)
    * this may be a proxy connection from our NAT, so remember this, and don't
    * inspect the remote addresses in the TCP tables.
    */
-  if (get_default_gw(q->ao->af, &s[0].addr) &&
+  if (!get_default_gw(q->ao->af, &s[0].addr) &&
       q->ao->addreq(&s[0].addr, &q->s[R].addr))
     gwp = 1;