aboutsummaryrefslogtreecommitdiff
path: root/src/common/address.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-11-27 22:18:16 -0500
committerNick Mathewson <nickm@torproject.org>2012-11-27 22:18:16 -0500
commit190c1d4981e5751aabd3d894095851c830f1d570 (patch)
treea832d932339382cb7f43fb33a255d7507e037c2e /src/common/address.c
parent267c0e5aa14deeb2ca0d7997b4ef5a5c2bbf5fd4 (diff)
parent6f21d2e49657ada264cace9da7cf6945b4fc073d (diff)
downloadtor-190c1d4981e5751aabd3d894095851c830f1d570.tar
tor-190c1d4981e5751aabd3d894095851c830f1d570.tar.gz
Merge branch 'bug7013_take2_squashed'
Diffstat (limited to 'src/common/address.c')
-rw-r--r--src/common/address.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c
index e94f147ce..3b844f799 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1430,7 +1430,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. */