chiark / gitweb /
noip.c (do_implicit_bind): Handle `SAME' impbind entries properly.
[preload-hacks] / noip.c
diff --git a/noip.c b/noip.c
index f60788e3940d6988c8df8b0be77c427718f9dace..345f3251d7c56d2e591fedee22b663e8b330e505 100644 (file)
--- a/noip.c
+++ b/noip.c
 #include <ifaddrs.h>
 #include <netdb.h>
 
+#ifndef SUN_LEN
+#  define SUN_LEN (sun) \
+       (strlen((sun)->sun_path) + offsetof(struct sockaddr_un, sun_path))
+#endif
+
 /*----- Data structures ---------------------------------------------------*/
 
 /* Unix socket status values. */
@@ -1122,7 +1127,11 @@ static int do_implicit_bind(int sk, const struct sockaddr *sa, unsigned f)
        sockaddr_in_range_p(sa, &i->minaddr, &i->maxaddr)) {
       D( fprintf(stderr, "noip(%d): match!\n", pid); )
       addr.sa.sa_family = sa->sa_family;
-      ipaddr_to_sockaddr(&addr.sa, &i->bindaddr);
+      switch (i->how) {
+       case EXPLICIT: ipaddr_to_sockaddr(&addr.sa, &i->bindaddr); break;
+       case SAME: copy_sockaddr(&addr.sa, sa); break;
+      }
+      port_to_sockaddr(&addr.sa, 0);
       goto found;
     }
   }
@@ -1965,7 +1974,7 @@ int getpeername(int sk, struct sockaddr *sa, socklen_t *len)
     D( fprintf(stderr, "noip(%d): ... GETPEERNAME", pid); )
   }
   D( dump_addrresult(rc, sa, *len); )
-  return (0);
+  return (rc);
 }
 
 int getsockopt(int sk, int lev, int opt, void *p, socklen_t *len)