diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-01-26 11:59:01 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-01-26 12:08:15 -0500 |
commit | 6ed384b827dce21ea3a44b58792cc28b2ed48056 (patch) | |
tree | 7f4e7f5af7ef3cb21dae370cb0f0e0f2acc16b7d /src/common/address.c | |
parent | 2a7bfec364a30a92c3babe658ece2db1a8a40d03 (diff) | |
download | tor-6ed384b827dce21ea3a44b58792cc28b2ed48056.tar.gz tor-6ed384b827dce21ea3a44b58792cc28b2ed48056.zip |
Use tor_addr_from_getsockname() in several places
I'm leaving the getsockname code in transproxy alone, since it is
comparatively isolated, rather platform-specific, and hard to test.
Implements 18105.
Diffstat (limited to 'src/common/address.c')
-rw-r--r-- | src/common/address.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/common/address.c b/src/common/address.c index d96ec514b1..7d0fa5614c 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1672,7 +1672,7 @@ get_interface_address6_via_udp_socket_hack,(int severity, sa_family_t family, tor_addr_t *addr)) { - struct sockaddr_storage my_addr, target_addr; + struct sockaddr_storage target_addr; int sock=-1, r=-1; socklen_t addr_len; @@ -1715,21 +1715,19 @@ get_interface_address6_via_udp_socket_hack,(int severity, goto err; } - if (tor_getsockname(sock,(struct sockaddr*)&my_addr, &addr_len)) { + if (tor_addr_from_getsockname(addr, sock) < 0) { int e = tor_socket_errno(sock); log_fn(severity, LD_NET, "getsockname() to determine interface failed: %s", tor_socket_strerror(e)); goto err; } - if (tor_addr_from_sockaddr(addr, (struct sockaddr*)&my_addr, NULL) == 0) { - if (tor_addr_is_loopback(addr) || tor_addr_is_multicast(addr)) { - log_fn(severity, LD_NET, "Address that we determined via UDP socket" - " magic is unsuitable for public comms."); - } else { - r=0; - } - } + if (tor_addr_is_loopback(addr) || tor_addr_is_multicast(addr)) { + log_fn(severity, LD_NET, "Address that we determined via UDP socket" + " magic is unsuitable for public comms."); + } else { + r=0; + } err: if (sock >= 0) |