noip.c: Fix some holdovers with hardcoded address families.
[preload-hacks] / noip.c
diff --git a/noip.c b/noip.c
index 9c5cd68..a1e141a 100644 (file)
--- a/noip.c
+++ b/noip.c
@@ -285,6 +285,7 @@ static void port_to_sockaddr(struct sockaddr *sa, int port)
     default: abort();
   }
 }
+
 /* Extract the address part from SA and store it in A. */
 static void ipaddr_from_sockaddr(ipaddr *a, const struct sockaddr *sa)
 {
@@ -353,7 +354,7 @@ static void wildcard_address(int af, struct sockaddr *sa)
     } break;
     case AF_INET6: {
       struct sockaddr_in6 *sin6 = SIN6(sa);
-      memset(sin6, 0, sizeof(sin6));
+      memset(sin6, 0, sizeof(*sin6));
       sin6->sin6_family = AF_INET6;
       sin6->sin6_port = 0;
       sin6->sin6_addr = in6addr_any;
@@ -502,7 +503,7 @@ static int parse_sockaddr(struct sockaddr *sa, const char *p)
 #ifdef DEBUG
 
 /* Write to standard error a description of the ACL node A. */
-static void dump_aclnode(aclnode *a)
+static void dump_aclnode(const aclnode *a)
 {
   char buf[ADDRBUFSZ];
   const char *p;
@@ -525,7 +526,7 @@ static void dump_aclnode(aclnode *a)
   fputc('\n', stderr);
 }
 
-static void dump_acl(aclnode *a)
+static void dump_acl(const aclnode *a)
 {
   int act = ALLOW;
 
@@ -540,7 +541,7 @@ static void dump_acl(aclnode *a)
 #endif
 
 /* Returns nonzero if the ACL A allows the socket address SA. */
-static int acl_allows_p(aclnode *a, const struct sockaddr *sa)
+static int acl_allows_p(const aclnode *a, const struct sockaddr *sa)
 {
   unsigned short port = port_from_sockaddr(sa);
   int act = ALLOW;
@@ -677,10 +678,10 @@ static int encode_inet_addr(struct sockaddr_un *sun,
 }
 
 /* Decode the Unix address SUN to an Internet address SIN.  If AF_HINT is
- * nonzero, an empty address (indicative of an unbound Unix-domain socket) of
- * the is translated to a wildcard Internet address of the appropriate
- * family.  Returns zero on success; -1 on failure (e.g., it wasn't one of
- * our addresses).
+ * nonzero, an empty address (indicative of an unbound Unix-domain socket) is
+ * translated to a wildcard Internet address of the appropriate family.
+ * Returns zero on success; -1 on failure (e.g., it wasn't one of our
+ * addresses).
  */
 static int decode_inet_addr(struct sockaddr *sa, int af_hint,
                            const struct sockaddr_un *sun,
@@ -1037,8 +1038,9 @@ static void parse_acl_line(char **pp, aclnode ***tail)
     }
     SKIPSPC;
     if (*p != ',') break;
-    p++;
+    if (*p) p++;
   }
+  *pp = p;
   return;
 
 bad:
@@ -1059,6 +1061,7 @@ static void parse_autoports(char **pp)
   if (*p != '-') goto bad; p++;
   NEXTNUMBER(q, del); y = strtoul(q, 0, 0); RESCAN(del);
   minautoport = x; maxautoport = y;
+  *pp = p;
   return;
 
 bad:
@@ -1172,7 +1175,7 @@ int socket(int pf, int ty, int proto)
 
 int socketpair(int pf, int ty, int proto, int *sk)
 {
-  if (pf == PF_INET) {
+  if (family_known_p(pf)) {
     pf = PF_UNIX;
     proto = 0;
   }
@@ -1224,7 +1227,7 @@ ssize_t sendto(int sk, const void *buf, size_t len, int flags,
 {
   struct sockaddr_un sun;
 
-  if (to && to->sa_family == AF_INET) {
+  if (to && family_known_p(to->sa_family)) {
     PRESERVING_ERRNO({
       do_implicit_bind(sk, &to, &tolen, &sun);
     });
@@ -1256,7 +1259,7 @@ ssize_t sendmsg(int sk, const struct msghdr *msg, int flags)
   const struct sockaddr *sa;
   struct msghdr mymsg;
 
-  if (msg->msg_name && SA(msg->msg_name)->sa_family == AF_INET) {
+  if (msg->msg_name && family_known_p(SA(msg->msg_name)->sa_family)) {
     PRESERVING_ERRNO({
       sa = SA(msg->msg_name);
       mymsg = *msg;
@@ -1436,13 +1439,13 @@ static void create_sockdir(void)
 {
   struct stat st;
 
-  if (stat(sockdir, &st)) {
+  if (lstat(sockdir, &st)) {
     if (errno == ENOENT) {
       if (mkdir(sockdir, 0700)) {
        perror("noip: creating socketdir");
        exit(127);
       }
-      if (!stat(sockdir, &st))
+      if (!lstat(sockdir, &st))
        goto check;
     }
     perror("noip: checking socketdir");