|
@@ -33,28 +33,12 @@ typedef struct tor_addr_t
|
|
|
} addr;
|
|
|
} tor_addr_t;
|
|
|
|
|
|
-/** Return an IPv4 address in network order for <b>a</b>, or 0 if
|
|
|
- * <b>a</b> is not an IPv4 address. */
|
|
|
+static INLINE const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a);
|
|
|
static INLINE uint32_t tor_addr_to_ipv4n(const tor_addr_t *a);
|
|
|
-/** Return an IPv4 address in host order for <b>a</b>, or 0 if
|
|
|
- * <b>a</b> is not an IPv4 address. */
|
|
|
static INLINE uint32_t tor_addr_to_ipv4h(const tor_addr_t *a);
|
|
|
-/* Given an IPv6 address, return its mapped IPv4 address in host order, or
|
|
|
- * 0 if <b>a</b> is not an IPv6 address.
|
|
|
- *
|
|
|
- * (Does not check whether the address is really a mapped address */
|
|
|
static INLINE uint32_t tor_addr_to_mapped_ipv4h(const tor_addr_t *a);
|
|
|
-/** Return the address family of <b>a</b>. Possible values are:
|
|
|
- * AF_INET6, AF_INET, AF_UNSPEC. */
|
|
|
static INLINE sa_family_t tor_addr_family(const tor_addr_t *a);
|
|
|
-/** Return an in_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
- * an IPv4 address. */
|
|
|
static INLINE const struct in_addr *tor_addr_to_in(const tor_addr_t *a);
|
|
|
-/** Return an in6_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
- * an IPv6 address. */
|
|
|
-static INLINE const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a);
|
|
|
-/** Return true iff <b>a</b> is an IPv4 address equal to the host-ordered
|
|
|
- * address in <b>u</b>. */
|
|
|
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,
|
|
@@ -63,6 +47,8 @@ int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa,
|
|
|
uint16_t *port_out);
|
|
|
void tor_addr_make_unspec(tor_addr_t *a);
|
|
|
|
|
|
+/** Return an in6_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
+ * an IPv6 address. */
|
|
|
static INLINE const struct in6_addr *
|
|
|
tor_addr_to_in6(const tor_addr_t *a)
|
|
|
{
|
|
@@ -73,31 +59,45 @@ tor_addr_to_in6(const tor_addr_t *a)
|
|
|
#define tor_addr_to_in6_addr16(x) S6_ADDR16(*tor_addr_to_in6(x))
|
|
|
#define tor_addr_to_in6_addr32(x) S6_ADDR32(*tor_addr_to_in6(x))
|
|
|
|
|
|
+/** Return an IPv4 address in network order for <b>a</b>, or 0 if
|
|
|
+ * <b>a</b> is not an IPv4 address. */
|
|
|
static INLINE uint32_t
|
|
|
tor_addr_to_ipv4n(const tor_addr_t *a)
|
|
|
{
|
|
|
return a->family == AF_INET ? a->addr.in_addr.s_addr : 0;
|
|
|
}
|
|
|
+/** Return an IPv4 address in host order for <b>a</b>, or 0 if
|
|
|
+ * <b>a</b> is not an IPv4 address. */
|
|
|
static INLINE uint32_t
|
|
|
tor_addr_to_ipv4h(const tor_addr_t *a)
|
|
|
{
|
|
|
return ntohl(tor_addr_to_ipv4n(a));
|
|
|
}
|
|
|
+/* Given an IPv6 address, return its mapped IPv4 address in host order, or
|
|
|
+ * 0 if <b>a</b> is not an IPv6 address.
|
|
|
+ *
|
|
|
+ * (Does not check whether the address is really a mapped address */
|
|
|
static INLINE uint32_t
|
|
|
tor_addr_to_mapped_ipv4h(const tor_addr_t *a)
|
|
|
{
|
|
|
return a->family == AF_INET6 ? ntohl(tor_addr_to_in6_addr32(a)[3]) : 0;
|
|
|
}
|
|
|
+/** Return the address family of <b>a</b>. Possible values are:
|
|
|
+ * AF_INET6, AF_INET, AF_UNSPEC. */
|
|
|
static INLINE sa_family_t
|
|
|
tor_addr_family(const tor_addr_t *a)
|
|
|
{
|
|
|
return a->family;
|
|
|
}
|
|
|
+/** Return an in_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
+ * an IPv4 address. */
|
|
|
static INLINE const struct in_addr *
|
|
|
tor_addr_to_in(const tor_addr_t *a)
|
|
|
{
|
|
|
return a->family == AF_INET ? &a->addr.in_addr : NULL;
|
|
|
}
|
|
|
+/** Return true iff <b>a</b> is an IPv4 address equal to the host-ordered
|
|
|
+ * address in <b>u</b>. */
|
|
|
static INLINE int
|
|
|
tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
|
|
|
{
|