summaryrefslogtreecommitdiff
path: root/src/common/address.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-08-07 19:13:35 +0000
committerNick Mathewson <nickm@torproject.org>2008-08-07 19:13:35 +0000
commitd9601c65e0529c1f79e52ca3576cbc8f0a82f8f6 (patch)
tree7025b74af0ad9c3bfb8a0ce6953864787d150e6a /src/common/address.c
parent635f3c8aeef717d03a86117dfa81944fb6788bca (diff)
downloadtor-d9601c65e0529c1f79e52ca3576cbc8f0a82f8f6.tar.gz
tor-d9601c65e0529c1f79e52ca3576cbc8f0a82f8f6.zip
r17666@tombo: nickm | 2008-08-07 15:12:30 -0400
Make tor_addr_from_sockaddr also give away the port in a useful format svn:r16458
Diffstat (limited to 'src/common/address.c')
-rw-r--r--src/common/address.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c
index e5b11a4ffd..ac4ae041d8 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -94,7 +94,8 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
/** Set the tor_addr_t in <b>a</b> to contain the socket address contained in
* <b>sa</b>. */
int
-tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa)
+tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa,
+ uint16_t *port_out)
{
tor_assert(a);
tor_assert(sa);
@@ -103,10 +104,14 @@ tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa)
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
a->family = AF_INET;
a->addr.in_addr.s_addr = sin->sin_addr.s_addr;
+ if (port_out)
+ *port_out = ntohs(sin->sin_port);
} else if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
a->family = AF_INET6;
memcpy(&a->addr.in6_addr, &sin6->sin6_addr, sizeof(struct in6_addr));
+ if (port_out)
+ *port_out = ntohs(sin6->sin6_port);
} else {
a->family = AF_UNSPEC;
return -1;