I've just been trying to update a socks server to support IPv6 and found that nc wasn't consuming all of the socks connect reply. I think that this patch fixes this.
Index: socks.c =================================================================== RCS file: /cvs/src/usr.bin/nc/socks.c,v retrieving revision 1.17 diff -u -p socks.c --- socks.c 25 Sep 2006 04:51:20 -0000 1.17 +++ socks.c 3 Jun 2009 13:13:07 -0000 @@ -222,11 +222,24 @@ socks_connect(const char *host, const char *port, if (cnt != wlen) err(1, "write failed (%d/%d)", cnt, wlen); - cnt = atomicio(read, proxyfd, buf, 10); - if (cnt != 10) - err(1, "read failed (%d/10)", cnt); + cnt = atomicio(read, proxyfd, buf, 4); + if (cnt != 4) + err(1, "read failed (%d/4)", cnt); if (buf[1] != 0) errx(1, "connection failed, SOCKS error %d", buf[1]); + switch (buf[3]) + { + case SOCKS_IPV4: + cnt = atomicio(read, proxyfd, buf + 4, 6); + if (cnt != 6) + err(1, "read failed (%d/6)", cnt); + break; + case SOCKS_IPV6: + cnt = atomicio(read, proxyfd, buf + 4, 18); + if (cnt != 18) + err(1, "read failed (%d/18)", cnt); + break; + } } else if (socksv == 4) { /* This will exit on lookup failure */ decode_addrport(host, port, (struct sockaddr *)&addr,