}
/** Similar behavior to Unix gethostbyname: resolve <b>name</b>, and set
- * *<b>addr</b> to the proper IP address and family.
+ * *<b>addr</b> to the proper IP address and family. The <b>family</b>
+ * argument (which must be AF_INET, AF_INET6, or AF_UNSPEC) declares a
+ * <i>preferred</i> family, though another one may be returned if only one
+ * family is implemented for this address.
+ *
* Return 0 on success, -1 on failure; 1 on transient failure.
- * DOCDOC family argument.
*/
int
tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr)
* <b>addr_out</b>, a mask (if any) in <b>mask_out</b>, and port(s) (if any)
* in <b>port_min_out</b> and <b>port_max_out</b>.
*
- * DOCDOC exact syntax.
+ * The syntax is:
+ * Address OptMask OptPortRange
+ * Address ::= IPv4Address / "[" IPv6Address "]" / "*"
+ * OptMask ::= "/" Integer /
+ * OptPortRange ::= ":*" / ":" Integer / ":" Integer "-" Integer /
*
- * - If mask, minport, or maxport are NULL, avoid storing those elements.
+ * - If mask, minport, or maxport are NULL, we do not want these
+ * options to be set; treat them as an error if present.
* - If the string has no mask, the mask is set to /32 (IPv4) or /128 (IPv6).
* - If the string has one port, it is placed in both min and max port
* variables.
memcpy(dest, src, sizeof(tor_addr_t));
}
-/** DOCDOC */
+/** Given two addresses <b>addr1</b> and <b>addr2</b>, return 0 if the two
+ * addresses are equivalent under the mask mbits, less than 0 if addr1
+ * preceeds addr2, and greater than 0 otherwise.
+ *
+ * Different address families (IPv4 vs IPv6) are always considered unequal.
+ */
int
tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2)
{
return tor_addr_compare_masked(addr1, addr2, 128);
}
-/** Given two addresses <b>addr1</b> and <b>addr2</b>, return 0 if the two
- * addresses are equivalent under the mask mbits, or nonzero if not.
- *
- * Different address families (IPv4 vs IPv6) are always considered unequal.
+/** As tor_addr_compare(), but only looks at the first <b>mask</b> bits of
+ * the address.
*
* Reduce over-specific masks (>128 for ipv6, >32 for ipv4) to 128 or 32.
*/
tor_assert(addr1 && addr2);
+ /* XXXX020 this code doesn't handle mask bits right it's using v4-mapped v6
+ * addresses. If I ask whether ::ffff:1.2.3.4 and ::ffff:1.2.7.8 are the
+ * same in the first 16 bits, it will say "yes." That's not so intuitive.
+ */
+
v_family[0] = IN_FAMILY(addr1);
v_family[1] = IN_FAMILY(addr2);
}
/** Convert the tor_addr_t *<b>addr</b> into string form and store it in
- * <b>dest</b> (no more than <b>len</b> bytes). DOCDOC return value.
+ * <b>dest</b>, which can hold at least <b>len</b> bytes. Returns <b>dest</b>
+ * on success, NULL on failure.
*/
const char *
tor_addr_to_str(char *dest, const tor_addr_t *addr, int len)