commit 4599120dd5e6ebba4fda2b1d4a9e912a638e7e8e Author: George Kadianakis desnacked@riseup.net Date: Mon Jan 16 19:21:48 2012 +0200
Don't use 'int' to store TCP ports. 'uint16_t' is nicer.
'uint16_t' also makes our asserts look more reasonable. --- src/network.c | 7 ++++--- src/socks.c | 5 +++-- src/socks.h | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/network.c b/src/network.c index 4cdd059..a28f7b8 100644 --- a/src/network.c +++ b/src/network.c @@ -559,7 +559,7 @@ open_outbound(conn_t *conn, bufferevent_data_cb readcb) rather than bufferevent_socket_connect. */ static conn_t * -open_outbound_hostname(conn_t *conn, int af, const char *addr, int port) +open_outbound_hostname(conn_t *conn, int af, const char *addr, uint16_t port) { struct event_base *base = bufferevent_get_base(conn->buffer); struct bufferevent *buf; @@ -604,7 +604,7 @@ open_outbound_hostname(conn_t *conn, int af, const char *addr, int port) bufferevent_setcb(buf, downstream_read_cb, NULL, pending_socks_cb, newconn); if (bufferevent_socket_connect_hostname(buf, get_evdns_base(), af, addr, port) < 0) { - log_warn("%s: outbound connection to %s:%d failed: %s", + log_warn("%s: outbound connection to %s:%u failed: %s", conn->peername, addr, port, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR())); conn_free(newconn); @@ -638,7 +638,8 @@ socks_read_cb(struct bufferevent *bev, void *arg) /* We shouldn't be here. */ obfs_abort(); } else if (status == ST_HAVE_ADDR) { - int af, r, port; + int af, r; + uint16_t port; const char *addr=NULL; r = socks_state_get_address(socks, &af, &addr, &port); obfs_assert(r==0); diff --git a/src/socks.c b/src/socks.c index 98cb678..e76a24e 100644 --- a/src/socks.c +++ b/src/socks.c @@ -569,7 +569,7 @@ int socks_state_get_address(const socks_state_t *state, int *af_out, const char **addr_out, - int *port_out) + uint16_t *port_out) { if (state->state != ST_HAVE_ADDR && state->state != ST_SENT_REPLY) return -1; @@ -586,9 +586,10 @@ socks_state_get_address(const socks_state_t *state, int socks_state_set_address(socks_state_t *state, const struct sockaddr *sa) { - int port; + uint16_t port; if (sa->sa_family == AF_INET) { const struct sockaddr_in *sin = (const struct sockaddr_in *)sa; + obfs_assert((sin->sin_port >= 0) && (sin->sin_port <= 65535)); port = sin->sin_port; if (evutil_inet_ntop(AF_INET, &sin->sin_addr, state->parsereq.addr, sizeof(state->parsereq.addr)) == NULL) diff --git a/src/socks.h b/src/socks.h index 4e0bdfa..384838f 100644 --- a/src/socks.h +++ b/src/socks.h @@ -38,7 +38,7 @@ enum socks_status_t socks_state_get_status(const socks_state_t *state); int socks_state_get_address(const socks_state_t *state, int *af_out, const char **addr_out, - int *port_out); + uint16_t *port_out); int socks_state_set_address(socks_state_t *state, const struct sockaddr *sa); void socks_send_reply(socks_state_t *state, struct evbuffer *dest, int error); void socks5_send_reply(struct evbuffer *reply_dest, @@ -91,7 +91,7 @@ void socks5_send_reply(struct evbuffer *reply_dest, struct parsereq { int af; /* Address family */ char addr[255+1]; /* Address as string */ - int port; + uint16_t port; }; struct socks_state_t { enum socks_status_t state;
tor-commits@lists.torproject.org