aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-10 13:30:44 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-10 13:32:37 -0400
commit8de48c111c09d76ecd00bb9dec67acb47890db01 (patch)
tree6e08c4f8b548b27c935fb5fc8ddd9b53bf339c75
parent2f657a1416f2f81dd1be900269c4ae9bdb29f52d (diff)
downloadtor-8de48c111c09d76ecd00bb9dec67acb47890db01.tar.gz
tor-8de48c111c09d76ecd00bb9dec67acb47890db01.zip
Remove addr_port_lookup.
This lets us cut the dependency from address.c to resolve.c: the address.c module now has no paths to the libc resolver in it.
-rw-r--r--changes/ticket265264
-rw-r--r--src/lib/net/address.c42
2 files changed, 12 insertions, 34 deletions
diff --git a/changes/ticket26526 b/changes/ticket26526
new file mode 100644
index 0000000000..447b581df8
--- /dev/null
+++ b/changes/ticket26526
@@ -0,0 +1,4 @@
+ o Code simplification and refactoring:
+ - Utility functions that can perform a DNS lookup are now wholly
+ separated from those that can't, in separate headers and C
+ modules. Closes ticket 26526.
diff --git a/src/lib/net/address.c b/src/lib/net/address.c
index 1d872043a0..3b624da096 100644
--- a/src/lib/net/address.c
+++ b/src/lib/net/address.c
@@ -6,6 +6,9 @@
/**
* \file address.c
* \brief Functions to use and manipulate the tor_addr_t structure.
+ *
+ * This module doesn't have any support for the libc resolver: that is all in
+ * resolve.c.
**/
#define ADDRESS_PRIVATE
@@ -37,7 +40,6 @@
#include "lib/net/address.h"
#include "lib/net/socket.h"
-#include "lib/net/resolve.h"
#include "lib/container/smartlist.h"
#include "lib/ctime/di_ops.h"
#include "lib/log/torlog.h"
@@ -1748,7 +1750,7 @@ tor_addr_port_split(int severity, const char *addrport,
tor_assert(addrport);
tor_assert(address_out);
tor_assert(port_out);
- /* We need to check for IPv6 manually because addr_port_lookup() doesn't
+ /* We need to check for IPv6 manually because the logic below doesn't
* do a good job on IPv6 addresses that lack a port. */
if (tor_addr_parse(&a_tmp, addrport) == AF_INET6) {
*port_out = 0;
@@ -1756,30 +1758,11 @@ tor_addr_port_split(int severity, const char *addrport,
return 0;
}
- return addr_port_lookup(severity, addrport, address_out, NULL, port_out);
-}
-
-/** Parse a string of the form "host[:port]" from <b>addrport</b>. If
- * <b>address</b> is provided, set *<b>address</b> to a copy of the
- * host portion of the string. If <b>addr</b> is provided, try to
- * resolve the host portion of the string and store it into
- * *<b>addr</b> (in host byte order). If <b>port_out</b> is provided,
- * store the port number into *<b>port_out</b>, or 0 if no port is given.
- * If <b>port_out</b> is NULL, then there must be no port number in
- * <b>addrport</b>.
- * Return 0 on success, -1 on failure.
- */
-int
-addr_port_lookup(int severity, const char *addrport, char **address,
- uint32_t *addr, uint16_t *port_out)
-{
const char *colon;
char *address_ = NULL;
int port_;
int ok = 1;
- tor_assert(addrport);
-
colon = strrchr(addrport, ':');
if (colon) {
address_ = tor_strndup(addrport, colon-addrport);
@@ -1801,22 +1784,13 @@ addr_port_lookup(int severity, const char *addrport, char **address,
port_ = 0;
}
- if (addr) {
- /* There's an addr pointer, so we need to resolve the hostname. */
- if (tor_lookup_hostname(address_,addr)) {
- log_fn(severity, LD_NET, "Couldn't look up %s", escaped(address_));
- ok = 0;
- *addr = 0;
- }
- }
-
- if (address && ok) {
- *address = address_;
+ if (ok) {
+ *address_out = address_;
} else {
- if (address)
- *address = NULL;
+ *address_out = NULL;
tor_free(address_);
}
+
if (port_out)
*port_out = ok ? ((uint16_t) port_) : 0;