chiark / gitweb /
pkstream/pkstream.c: Introduce an `initsock' function which does nothing.
[tripe] / pkstream / pkstream.c
index 580bb73f3cb95ab2c3cbe8c4a0cd66de2c74e8d3..dd4658e4f6d7b5cb3b28f1ee1270925057582864 100644 (file)
@@ -111,6 +111,15 @@ static socklen_t addrsz(const addr *a)
   }
 }
 
+static int initsock(int fd, int af)
+{
+  switch (af) {
+    case AF_INET: break;
+    default: abort();
+  }
+  return (0);
+}
+
 static const char *addrstr(const addr *a)
 {
   static char buf[128];
@@ -312,6 +321,7 @@ static void dolisten1(const addr *a, sel_file *sf)
 
   if ((fd = socket(a->sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0 ||
       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) ||
+      initsock(fd, a->sa.sa_family) ||
       bind(fd, &a->sa, addrsz(a)) ||
       listen(fd, 1) || nonblockify(fd) || cloexec(fd))
     die(1, "couldn't set up listening socket: %s", strerror(errno));
@@ -507,6 +517,7 @@ int main(int argc, char *argv[])
 
     for (ai = ailist; ai; ai = ai->ai_next) {
       if ((fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
+         !initsock(fd, ai->ai_family) &&
          (!DA_LEN(&bindhosts) ||
           !bind(fd, &bindaddr.sa, addrsz(&bindaddr))) &&
          !connect(fd, ai->ai_addr, ai->ai_addrlen))
@@ -524,6 +535,7 @@ int main(int argc, char *argv[])
   aihint.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
   parseaddr(&aihint, argv[optind], 0, paf_parse, &ailist); ai = ailist;
   if ((fd_udp = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP)) < 0 ||
+      initsock(fd_udp, ai->ai_family) ||
       nonblockify(fd_udp) || cloexec(fd_udp) ||
       setsockopt(fd_udp, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) ||
       setsockopt(fd_udp, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len)) ||