diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-07-24 13:44:04 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-07-24 13:44:04 +0000 |
commit | 3ce6e2fba290eb5d3a4d0a3ca2f61658245b52b6 (patch) | |
tree | 08c562380df129cb4c8c896eecba0f3d8013d262 /src/common/compat.h | |
parent | ed781e69716248111ef1a2ddc1b9add671bd8d16 (diff) | |
download | tor-3ce6e2fba290eb5d3a4d0a3ca2f61658245b52b6.tar.gz tor-3ce6e2fba290eb5d3a4d0a3ca2f61658245b52b6.zip |
r17346@aud-055: nickm | 2008-07-24 15:37:19 +0200
Make generic address manipulation functions work better. Switch address policy code to use tor_addr_t, so it can handle IPv6. That is a good place to start.
svn:r16178
Diffstat (limited to 'src/common/compat.h')
-rw-r--r-- | src/common/compat.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 7ad964c75d..596a7058fe 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -361,17 +361,18 @@ typedef struct tor_addr_t /* DOCDOC*/ static INLINE uint32_t tor_addr_to_ipv4n(const tor_addr_t *a); static INLINE uint32_t tor_addr_to_ipv4h(const tor_addr_t *a); -static INLINE uint32_t tor_addr_to_mapped_ipv4n(const tor_addr_t *a); +static INLINE uint32_t tor_addr_to_mapped_ipv4h(const tor_addr_t *a); static INLINE sa_family_t tor_addr_family(const tor_addr_t *a); static INLINE const struct in_addr *tor_addr_to_in(const tor_addr_t *a); static INLINE const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a); socklen_t tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port, struct sockaddr *sa_out); +void tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa); static INLINE const struct in6_addr * tor_addr_to_in6(const tor_addr_t *a) { - return &a->addr.in6_addr; + return a->family == AF_INET6 ? &a->addr.in6_addr : NULL; } #define tor_addr_to_in6_addr16(x) S6_ADDR16(*tor_addr_to_in6(x)) @@ -380,7 +381,7 @@ tor_addr_to_in6(const tor_addr_t *a) static INLINE uint32_t tor_addr_to_ipv4n(const tor_addr_t *a) { - return a->addr.in_addr.s_addr; + return a->family == AF_INET ? a->addr.in_addr.s_addr : 0; } static INLINE uint32_t tor_addr_to_ipv4h(const tor_addr_t *a) @@ -388,7 +389,7 @@ tor_addr_to_ipv4h(const tor_addr_t *a) return ntohl(tor_addr_to_ipv4n(a)); } static INLINE uint32_t -tor_addr_to_mapped_ipv4n(const tor_addr_t *a) +tor_addr_to_mapped_ipv4h(const tor_addr_t *a) { return ntohl(tor_addr_to_in6_addr32(a)[3]); } @@ -400,11 +401,12 @@ tor_addr_family(const tor_addr_t *a) static INLINE const struct in_addr * tor_addr_to_in(const tor_addr_t *a) { - return &a->addr.in_addr; + return a->family == AF_INET ? &a->addr.in_addr : NULL; } #define INET_NTOA_BUF_LEN 16 /* 255.255.255.255 */ -#define TOR_ADDR_BUF_LEN 46 /* ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255 */ +#define TOR_ADDR_BUF_LEN 48 /* [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255] + */ int tor_inet_aton(const char *cp, struct in_addr *addr) ATTR_NONNULL((1,2)); const char *tor_inet_ntop(int af, const void *src, char *dst, size_t len); |