aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2012-11-28 00:24:58 +0200
committerNick Mathewson <nickm@torproject.org>2012-11-27 22:18:08 -0500
commit6f21d2e49657ada264cace9da7cf6945b4fc073d (patch)
treeb31176e1421128aa2b5a270abb8ff9e4a560e4cc /src/common
parentf88c3038697b00f50b2da12f46fc76ee0e20d646 (diff)
downloadtor-6f21d2e49657ada264cace9da7cf6945b4fc073d.tar
tor-6f21d2e49657ada264cace9da7cf6945b4fc073d.tar.gz
Introduce tor_addr_port_parse() and use it to parse ServerTransportListenAddr.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/address.c41
-rw-r--r--src/common/address.h3
2 files changed, 43 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c
index a714ead5e..fff3206a0 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1393,7 +1393,46 @@ 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
+/** Given an address of the form "ip:port", try to divide it into its
+ * ip and port portions, setting *<b>address_out</b> to a newly
+ * allocated string holding the address portion and *<b>port_out</b>
+ * to the port.
+ *
+ * Don't do DNS lookups and don't allow domain names in the <ip> field.
+ * Don't accept <b>addrport</b> of the form "<ip>" or "<ip>:0".
+ *
+ * Return 0 on success, -1 on failure. */
+int
+tor_addr_port_parse(int severity, const char *addrport,
+ tor_addr_t *address_out, uint16_t *port_out)
+{
+ int retval = -1;
+ int r;
+ char *addr_tmp = NULL;
+
+ tor_assert(addrport);
+ tor_assert(address_out);
+ tor_assert(port_out);
+
+ r = tor_addr_port_split(severity, addrport, &addr_tmp, port_out);
+ if (r < 0)
+ goto done;
+
+ if (!*port_out)
+ goto done;
+
+ /* make sure that address_out is an IP address */
+ if (tor_addr_parse(address_out, addr_tmp) < 0)
+ goto done;
+
+ retval = 0;
+
+ done:
+ tor_free(addr_tmp);
+ return retval;
+}
+
+/** 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. */
diff --git a/src/common/address.h b/src/common/address.h
index 067b7a0ca..61c6eb80e 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -206,6 +206,9 @@ 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);
+int tor_addr_port_parse(int severity, const char *addrport,
+ tor_addr_t *address_out, uint16_t *port_out);
+
int tor_addr_hostname_is_local(const char *name);
/* IPv4 helpers */