[tor-commits] [obfsproxy/master] * Fixed a small bug in socks5_send_reply() found by the unit tests.
nickm at torproject.org
nickm at torproject.org
Tue May 24 01:24:02 UTC 2011
commit d9c15cebf1ace2bf4e14022f9711bfee275aca05
Author: George Kadianakis <desnacked at gmail.com>
Date: Tue May 24 00:43:54 2011 +0200
* Fixed a small bug in socks5_send_reply() found by the unit tests.
* de-staticed the socks4_* functions, so that they can be unit tested.
* Changed the way socks4_send_reply() returns, to something I'm not
sure I like or find useful; but that's how socks5_send_reply() was.
---
src/socks.c | 15 +++++++++++----
src/socks.h | 5 ++++-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/socks.c b/src/socks.c
index a1f794a..5a97b83 100644
--- a/src/socks.c
+++ b/src/socks.c
@@ -202,7 +202,7 @@ socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state,
} else {
addrlen = (state->parsereq.af == AF_INET) ? 4 : 16;
p[3] = (state->parsereq.af == AF_INET) ? SOCKS5_ATYP_IPV4 : SOCKS5_ATYP_IPV6;
- evutil_inet_pton(AF_INET, state->parsereq.addr, addr);
+ evutil_inet_pton(state->parsereq.af, state->parsereq.addr, addr);
}
port = htons(state->parsereq.port);
@@ -293,7 +293,8 @@ socks5_do_negotiation(struct evbuffer *dest, unsigned int neg_was_success)
return 1;
}
-static int
+/* rename to socks4_handle_request or something. */
+int
socks4_read_request(struct evbuffer *source, socks_state_t *state)
{
/* Format is:
@@ -366,7 +367,7 @@ socks4_read_request(struct evbuffer *source, socks_state_t *state)
return 1;
}
-static int
+int
socks4_send_reply(struct evbuffer *dest, socks_state_t *state, int status)
{
uint16_t portnum;
@@ -381,9 +382,15 @@ socks4_send_reply(struct evbuffer *dest, socks_state_t *state, int status)
/* convert to socks4 status */
msg[1] = (status == SOCKS5_REP_SUCCESS) ? SOCKS4_SUCCESS : SOCKS4_FAILED;
memcpy(msg+2, &portnum, 2);
+ /* ASN: What should we do here in the case of an FQDN request? */
memcpy(msg+4, &in.s_addr, 4);
evbuffer_add(dest, msg, 8);
- return 1;
+
+ /* ASN: Do we actually like this return tactic? Check out why I do it. */
+ if (status == SOCKS5_REP_SUCCESS)
+ return 1;
+ else
+ return -1;
}
/**
diff --git a/src/socks.h b/src/socks.h
index 36a5a32..37c94cc 100644
--- a/src/socks.h
+++ b/src/socks.h
@@ -84,9 +84,12 @@ int socks5_handle_negotiation(struct evbuffer *source,
struct evbuffer *dest, socks_state_t *state);
int socks5_handle_request(struct evbuffer *source,
struct parsereq *parsereq);
-
int socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state,
int status);
+
+int socks4_read_request(struct evbuffer *source, socks_state_t *state);
+int socks4_send_reply(struct evbuffer *dest,
+ socks_state_t *state, int status);
#endif
#endif
More information about the tor-commits
mailing list