chiark / gitweb /
udp: Support IPv6 when using authbind
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Sep 2014 21:48:45 +0000 (22:48 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 2 Oct 2014 15:30:21 +0000 (16:30 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
udp.c

diff --git a/udp.c b/udp.c
index 334670f..b57c85c 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -269,20 +269,35 @@ static void udp_make_socket(struct udp *st, struct udpsock *us)
            fatal_perror("udp_phase_hook: fork() for authbind");
        }
        if (c==0) {
-           char *argv[4], addrstr[9], portstr[5];
+           char *argv[5], addrstr[33], portstr[5];
+           const char *addrfam;
+           int port;
            switch (addr->sa.sa_family) {
            case AF_INET:
                sprintf(addrstr,"%08lX",(long)addr->sin.sin_addr.s_addr);
-               sprintf(portstr,"%04X",addr->sin.sin_port);
+               port=addr->sin.sin_port;
+               addrfam=NULL;
                break;
+#ifdef CONFIG_IPV6
+           case AF_INET6: {
+               int i;
+               for (i=0; i<16; i++)
+                   sprintf(addrstr+i*2,"%02X",addr->sin6.sin6_addr.s6_addr[i]);
+               port=addr->sin6.sin6_port;
+               addrfam="6";
+               break;
+           }
+#endif /*CONFIG_IPV6*/
            default:
                fatal("udp (%s:%d): unsupported address family for authbind",
                      st->loc.file,st->loc.line);
            }
+           sprintf(portstr,"%04X",port);
            argv[0]=st->authbind;
            argv[1]=addrstr;
            argv[2]=portstr;
-           argv[3]=NULL;
+           argv[3]=(char*)addrfam;
+           argv[4]=NULL;
            dup2(us->fd,0);
            execvp(st->authbind,argv);
            _exit(255);