summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-10-11 12:02:19 -0400
committerNick Mathewson <nickm@torproject.org>2011-10-11 12:02:19 -0400
commit426f6bfda2440f4de99c4579be773dfbabac039f (patch)
tree54af81c24341f4b3f8369cbe28993922d05f717c /src/common
parent491e20ae13c3acdd6d18d994cc41178733a778b5 (diff)
downloadtor-426f6bfda2440f4de99c4579be773dfbabac039f.tar.gz
tor-426f6bfda2440f4de99c4579be773dfbabac039f.zip
Stop using addr_port_lookup as an address splitting function
It's too risky to have a function where if you leave one parameter NULL, it splits up address:port strings, but if you set it, it does hostname resolution.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/address.c16
-rw-r--r--src/common/address.h3
2 files changed, 18 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c
index 5c2b54015c..b41456f8de 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1148,6 +1148,20 @@ is_internal_IP(uint32_t ip, int for_listening)
return tor_addr_is_internal(&myaddr, for_listening);
}
+/** Given an address of the form "host:port", try to divide it into its host
+ * ane port portions, setting *<b>address_out</b> to a newly allocated string
+ * holding the address portion and *<b>port_out</b> to the port (or 0 if no
+ * port is given). Return 0 on success, -1 on failure. */
+int
+tor_addr_port_split(int severity, const char *addrport,
+ char **address_out, uint16_t *port_out)
+{
+ tor_assert(addrport);
+ tor_assert(address_out);
+ tor_assert(port_out);
+ 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
@@ -1169,7 +1183,7 @@ addr_port_lookup(int severity, const char *addrport, char **address,
tor_assert(addrport);
- colon = strchr(addrport, ':');
+ colon = strrchr(addrport, ':');
if (colon) {
_address = tor_strndup(addrport, colon-addrport);
_port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
diff --git a/src/common/address.h b/src/common/address.h
index 01aeb89799..359b0264d2 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -181,6 +181,9 @@ void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6);
int tor_addr_is_null(const tor_addr_t *addr);
int tor_addr_is_loopback(const tor_addr_t *addr);
+int tor_addr_port_split(int severity, const char *addrport,
+ char **address_out, uint16_t *port_out);
+
/* IPv4 helpers */
int is_internal_IP(uint32_t ip, int for_listening) ATTR_PURE;
int addr_port_lookup(int severity, const char *addrport, char **address,