aboutsummaryrefslogtreecommitdiffstats
path: root/socks.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2016-04-24 22:12:47 +0000
committerXin LI <delphij@FreeBSD.org>2016-04-24 22:12:47 +0000
commit09ac48e1c32eeedc204f8543f59cf29a7459298b (patch)
treeece78a3a8bdb725e9c7e47f96ddd59e9e66a230f /socks.c
parent70061f65353c351c2a0712f76d3e29a0164ce1dc (diff)
downloadsrc-09ac48e1c32eeedc204f8543f59cf29a7459298b.tar.gz
src-09ac48e1c32eeedc204f8543f59cf29a7459298b.zip
Vendor import nc(1) from OPENBSD_5_9.vendor/netcat/5.9
Notes
Notes: svn path=/vendor/netcat/dist/; revision=298554 svn path=/vendor/netcat/5.9/; revision=298555; tag=vendor/netcat/5.9
Diffstat (limited to 'socks.c')
-rw-r--r--socks.c66
1 files changed, 61 insertions, 5 deletions
diff --git a/socks.c b/socks.c
index 1b06e0e12dd5..c63cf3493954 100644
--- a/socks.c
+++ b/socks.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: socks.c,v 1.21 2015/03/26 21:19:51 tobias Exp $ */
+/* $OpenBSD: socks.c,v 1.23 2015/12/10 18:31:52 mmcc Exp $ */
/*
* Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
@@ -122,6 +122,58 @@ getproxypass(const char *proxyuser, const char *proxyhost)
return (pw);
}
+/*
+ * Error strings adapted from the generally accepted SOCKSv4 spec:
+ *
+ * http://ftp.icm.edu.pl/packages/socks/socks4/SOCKS4.protocol
+ */
+static const char *
+socks4_strerror(int e)
+{
+ switch (e) {
+ case 90:
+ return "Succeeded";
+ case 91:
+ return "Request rejected or failed";
+ case 92:
+ return "SOCKS server cannot connect to identd on the client";
+ case 93:
+ return "Client program and identd report different user-ids";
+ default:
+ return "Unknown error";
+ }
+}
+
+/*
+ * Error strings taken almost directly from RFC 1928.
+ */
+static const char *
+socks5_strerror(int e)
+{
+ switch (e) {
+ case 0:
+ return "Succeeded";
+ case 1:
+ return "General SOCKS server failure";
+ case 2:
+ return "Connection not allowed by ruleset";
+ case 3:
+ return "Network unreachable";
+ case 4:
+ return "Host unreachable";
+ case 5:
+ return "Connection refused";
+ case 6:
+ return "TTL expired";
+ case 7:
+ return "Command not supported";
+ case 8:
+ return "Address type not supported";
+ default:
+ return "Unknown error";
+ }
+}
+
int
socks_connect(const char *host, const char *port,
struct addrinfo hints __attribute__ ((__unused__)),
@@ -225,8 +277,10 @@ socks_connect(const char *host, const char *port,
cnt = atomicio(read, proxyfd, buf, 4);
if (cnt != 4)
err(1, "read failed (%zu/4)", cnt);
- if (buf[1] != 0)
- errx(1, "connection failed, SOCKS error %d", buf[1]);
+ if (buf[1] != 0) {
+ errx(1, "connection failed, SOCKSv5 error: %s",
+ socks5_strerror(buf[1]));
+ }
switch (buf[3]) {
case SOCKS_IPV4:
cnt = atomicio(read, proxyfd, buf + 4, 6);
@@ -261,8 +315,10 @@ socks_connect(const char *host, const char *port,
cnt = atomicio(read, proxyfd, buf, 8);
if (cnt != 8)
err(1, "read failed (%zu/8)", cnt);
- if (buf[1] != 90)
- errx(1, "connection failed, SOCKS error %d", buf[1]);
+ if (buf[1] != 90) {
+ errx(1, "connection failed, SOCKSv4 error: %s",
+ socks4_strerror(buf[1]));
+ }
} else if (socksv == -1) {
/* HTTP proxy CONNECT */