diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-15 20:17:31 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-15 20:17:31 -0500 |
commit | 3c8a481599cf9c84530db1f304731b5f2ec9caef (patch) | |
tree | 8e56236b24b3831812dd3f6fc594e2cea4092ef6 /src/common/compat.c | |
parent | 3e2b48f8b4eee456c4aa81f640185382642fa75c (diff) | |
parent | 6ed384b827dce21ea3a44b58792cc28b2ed48056 (diff) | |
download | tor-3c8a481599cf9c84530db1f304731b5f2ec9caef.tar.gz tor-3c8a481599cf9c84530db1f304731b5f2ec9caef.zip |
Merge branch 'bug18105'
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 4cb346dfa5..831813c1cc 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1392,6 +1392,24 @@ tor_getsockname,(tor_socket_t sock, struct sockaddr *address, return getsockname(sock, address, address_len); } +/** + * Find the local address associated with the socket <b>sock</b>, and + * place it in *<b>addr_out</b>. Return 0 on success, -1 on failure. + * + * (As tor_getsockname, but instead places the result in a tor_addr_t.) */ +int +tor_addr_from_getsockname(tor_addr_t *addr_out, tor_socket_t sock) +{ + struct sockaddr_storage ss; + socklen_t ss_len = sizeof(ss); + memset(&ss, 0, sizeof(ss)); + + if (tor_getsockname(sock, (struct sockaddr *) &ss, &ss_len) < 0) + return -1; + + return tor_addr_from_sockaddr(addr_out, (struct sockaddr *)&ss, NULL); +} + /** Turn <b>socket</b> into a nonblocking socket. Return 0 on success, -1 * on failure. */ |