aboutsummaryrefslogtreecommitdiff
path: root/src/common/address.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-08-05 20:08:19 +0000
committerNick Mathewson <nickm@torproject.org>2008-08-05 20:08:19 +0000
commit960a0f0a994ba23480e14ffe5179160194fd9616 (patch)
tree250494775699fda2f0f543a350b02e89c5a77a03 /src/common/address.h
parent750bb795ac1fcb5b76b6488690400c77fbff0a3f (diff)
downloadtor-960a0f0a994ba23480e14ffe5179160194fd9616.tar.gz
tor-960a0f0a994ba23480e14ffe5179160194fd9616.zip
r17641@31-33-44: nickm | 2008-08-05 16:07:53 -0400
Initial conversion of uint32_t addr to tor_addr_t addr in connection_t and related types. Most of the Tor wire formats using these new types are in, but the code to generate and use it is not. This is a big patch. Let me know what it breaks for you. svn:r16435
Diffstat (limited to 'src/common/address.h')
-rw-r--r--src/common/address.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/common/address.h b/src/common/address.h
index b079f69451..133a9b192d 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -40,7 +40,8 @@ static INLINE const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a);
static INLINE int tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u);
socklen_t tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port,
struct sockaddr *sa_out, socklen_t len);
-void tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa);
+int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa);
+void tor_addr_make_unspec(tor_addr_t *a);
static INLINE const struct in6_addr *
tor_addr_to_in6(const tor_addr_t *a)
@@ -88,9 +89,13 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
int tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out);
char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC;
+const char *fmt_addr(const tor_addr_t *addr);
int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr);
-/** DOCDOC */
+/** Flag to specify how to do a comparison between addresses. In an "exact"
+ * comparison, addresses are equivalent only if they are in the same family
+ * with the same value. In a "semantic" comparison, IPv4 addresses match all
+ * IPv6 encodings of those addresses. */
typedef enum {
CMP_EXACT,
CMP_SEMANTIC,
@@ -100,10 +105,15 @@ int tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2,
tor_addr_comparison_t how);
int tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
maskbits_t mask, tor_addr_comparison_t how);
+/** Return true iff a and b are the same address. The comparison is done
+ * "exactly". */
+#define tor_addr_eq(a,b) (0==tor_addr_compare((a),(b),CMP_EXACT))
unsigned int tor_addr_hash(const tor_addr_t *addr);
int tor_addr_is_v4(const tor_addr_t *addr);
int tor_addr_is_internal(const tor_addr_t *ip, int for_listening) ATTR_PURE;
+int tor_addr_port_parse(const char *s, tor_addr_t *addr_out,
+ uint16_t *port_out);
int tor_addr_parse_mask_ports(const char *s,
tor_addr_t *addr_out, maskbits_t *mask_out,
uint16_t *port_min_out, uint16_t *port_max_out);
@@ -111,7 +121,12 @@ const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, int len,
int decorate);
int tor_addr_from_str(tor_addr_t *addr, const char *src);
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src);
-void tor_addr_from_ipv4h(tor_addr_t *dest, uint32_t v4addr);
+void tor_addr_from_ipv4n(tor_addr_t *dest, uint32_t v4addr);
+/** Set <b>dest</b> to the IPv4 address encoded in <b>v4addr</b> in host
+ * order. */
+#define tor_addr_from_ipv4h(dest, v4addr) \
+ tor_addr_from_ipv4n((dest), htonl(v4addr))
+void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const char *byets);
int tor_addr_is_null(const tor_addr_t *addr);
int tor_addr_is_loopback(const tor_addr_t *addr);