20 #ifdef HAVE_NETINET_IN_H
21 #include <netinet/in.h>
31 #ifdef ADDRESS_PRIVATE
33 #if defined(HAVE_SYS_IOCTL_H)
34 #include <sys/ioctl.h>
37 #ifdef HAVE_GETIFADDRS
38 #define HAVE_IFADDRS_TO_SMARTLIST
42 #define HAVE_IP_ADAPTER_TO_SMARTLIST
45 #if defined(SIOCGIFCONF) && defined(HAVE_IOCTL)
46 #define HAVE_IFCONF_TO_SMARTLIST
49 #if defined(HAVE_NET_IF_H)
53 #if defined(HAVE_IFADDRS_TO_SMARTLIST)
74 struct in_addr in_addr;
86 #define TOR_ADDR_NULL {AF_UNSPEC, {0}}
103 struct sockaddr *sa_out, socklen_t len);
108 #define tor_addr_port_make_null(addr, port, family) \
109 (void)(tor_addr_make_null(addr, family), (port) = 0)
110 #define tor_addr_port_make_null_ap(ap, family) \
111 tor_addr_port_make_null(&(ap)->addr, (ap)->port, family)
116 static inline const struct in6_addr *
119 return a->family == AF_INET6 ? &a->addr.in6_addr : NULL;
124 static inline const struct in6_addr *
128 return &a->addr.in6_addr;
135 #define tor_addr_to_in6_addr8(x) tor_addr_to_in6_assert(x)->s6_addr
141 #define tor_addr_to_in6_addr16(x) S6_ADDR16(*tor_addr_to_in6_assert(x))
147 #define tor_addr_to_in6_addr32(x) S6_ADDR32(*tor_addr_to_in6_assert(x))
151 static inline uint32_t
154 return a->family == AF_INET ? a->addr.in_addr.s_addr : 0;
159 static inline uint32_t
169 static inline uint32_t
172 if (a->family == AF_INET6) {
173 uint32_t *addr32 = NULL;
178 return ntohl(addr32[3]);
198 return a->family == AF_UNSPEC;
203 static inline const struct in_addr *
206 return a->family == AF_INET ? &a->addr.in_addr : NULL;
224 #define TOR_ADDR_BUF_LEN 48
233 #define TOR_ADDRPORT_BUF_LEN (TOR_ADDR_BUF_LEN + 6)
239 #define fmt_addr(a) fmt_addr_impl((a), 0)
243 #define fmt_and_decorate_addr(a) fmt_addr_impl((a), 1)
247 #define fmt_addrport_ap(ap) fmt_addrport(&(ap)->addr, (ap)->port)
258 #define interface_address6_list_free(addrs) \
259 FREE_AND_NULL(struct smartlist_t, interface_address6_list_free_, (addrs))
263 int include_internal));
280 #define tor_addr_eq(a,b) (0==tor_addr_compare((a),(b),CMP_EXACT))
289 const char *filename,
int lineno);
290 #define tor_addr_is_internal(addr, for_listening) \
291 tor_addr_is_internal_((addr), (for_listening), SHORT_FILE__, __LINE__)
296 #define REVERSE_LOOKUP_NAME_BUF_LEN 73
300 int family,
int accept_regular);
306 #define TAPMP_EXTENDED_STAR 1
309 #define TAPMP_STAR_IPV4_ONLY (1 << 1)
312 #define TAPMP_STAR_IPV6_ONLY (1 << 2)
316 uint16_t *port_min_out, uint16_t *port_max_out);
327 #define tor_addr_from_ipv4h(dest, v4addr) \
328 tor_addr_from_ipv4n((dest), htonl(v4addr))
331 #define tor_addr_from_in(dest, in) \
332 tor_addr_from_ipv4n((dest), (in)->s_addr);
339 int tor_addr_is_valid(
const tor_addr_t *addr,
int for_listening);
340 int tor_addr_is_valid_ipv4n(uint32_t v4n_addr,
int for_listening);
341 #define tor_addr_is_valid_ipv4h(v4h_addr, for_listening) \
342 tor_addr_is_valid_ipv4n(htonl(v4h_addr), (for_listening))
343 int tor_port_is_valid(uint16_t port,
int for_listening);
346 #define tor_addr_port_is_valid(addr, port, for_listening) \
347 (tor_addr_is_valid((addr), (for_listening)) && \
348 tor_port_is_valid((port), (for_listening)))
350 #define tor_addr_port_is_valid_ap(ap, for_listening) \
351 tor_addr_port_is_valid(&(ap)->addr, (ap)->port, (for_listening))
353 #define tor_addr_port_is_valid_ipv4n(v4n_addr, port, for_listening) \
354 (tor_addr_is_valid_ipv4n((v4n_addr), (for_listening)) && \
355 tor_port_is_valid((port), (for_listening)))
357 #define tor_addr_port_is_valid_ipv4h(v4h_addr, port, for_listening) \
358 (tor_addr_is_valid_ipv4h((v4h_addr), (for_listening)) && \
359 tor_port_is_valid((port), (for_listening)))
362 char **address_out, uint16_t *port_out);
372 uint16_t *port_max_out);
377 #define interface_address_list_free(lst)\
378 interface_address6_list_free(lst)
404 #ifdef ADDRESS_PRIVATE
411 #ifdef HAVE_IFADDRS_TO_SMARTLIST
418 #ifdef HAVE_IP_ADAPTER_TO_SMARTLIST
420 const IP_ADAPTER_ADDRESSES *addresses);
425 #ifdef HAVE_IFCONF_TO_SMARTLIST
smartlist_t * get_interface_addresses_raw(int severity, sa_family_t family)
int get_interface_address6_via_udp_socket_hack(int severity, sa_family_t family, tor_addr_t *addr)
int string_is_valid_ipv6_address(const char *string)
uint64_t tor_addr_hash(const tor_addr_t *addr)
socklen_t tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port, struct sockaddr *sa_out, socklen_t len)
const char * fmt_addr_impl(const tor_addr_t *addr, int decorate)
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
void tor_addr_from_ipv4n(tor_addr_t *dest, uint32_t v4addr)
const char * fmt_addrport(const tor_addr_t *addr, uint16_t port)
static uint32_t tor_addr_to_ipv4n(const tor_addr_t *a)
void tor_addr_make_unspec(tor_addr_t *a)
char * tor_addr_to_str_dup(const tor_addr_t *addr) ATTR_MALLOC
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
int string_is_valid_ipv4_address(const char *string)
int tor_addr_hostname_is_local(const char *name)
static const struct in_addr * tor_addr_to_in(const tor_addr_t *a)
const char * fmt_af_family(sa_family_t family)
int tor_addr_parse(tor_addr_t *addr, const char *src)
void tor_addr_make_null(tor_addr_t *a, sa_family_t family)
int tor_addr_port_parse(int severity, const char *addrport, tor_addr_t *address_out, uint16_t *port_out, int default_port)
int string_is_valid_dest(const char *string)
int tor_addr_is_loopback(const tor_addr_t *addr)
static sa_family_t tor_addr_family(const tor_addr_t *a)
char * tor_dup_ip(uint32_t addr) ATTR_MALLOC
int get_interface_address(int severity, uint32_t *addr)
int string_is_valid_nonrfc_hostname(const char *string)
static struct smartlist_t * get_interface_address_list(int severity, int include_internal)
int tor_addr_is_v4(const tor_addr_t *addr)
int tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2, tor_addr_comparison_t how)
const char * fmt_addr32_port(uint32_t addr, uint16_t port)
void tor_addr_copy_ipv6_bytes(uint8_t *dest, const tor_addr_t *src)
const char * fmt_addr32(uint32_t addr)
int tor_addr_port_split(int severity, const char *addrport, char **address_out, uint16_t *port_out)
int tor_addr_is_null(const tor_addr_t *addr)
int tor_addr_parse_PTR_name(tor_addr_t *result, const char *address, int family, int accept_regular)
void tor_addr_port_copy(tor_addr_port_t *dest, const tor_addr_port_t *source)
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
static const struct in6_addr * tor_addr_to_in6(const tor_addr_t *a)
int tor_addr_is_multicast(const tor_addr_t *a)
void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const uint8_t *bytes)
const char * fmt_addr_family(const tor_addr_t *addr)
static uint32_t tor_addr_to_mapped_ipv4h(const tor_addr_t *a)
int addr_mask_get_bits(uint32_t mask)
int tor_addr_parse_mask_ports(const char *s, unsigned flags, tor_addr_t *addr_out, maskbits_t *mask_out, uint16_t *port_min_out, uint16_t *port_max_out)
static const struct in6_addr * tor_addr_to_in6_assert(const tor_addr_t *a)
int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
struct smartlist_t * get_interface_address6_list(int severity, sa_family_t family, int include_internal)
int tor_addr_is_v6(const tor_addr_t *addr)
void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6)
uint64_t tor_addr_keyed_hash(const struct sipkey *key, const tor_addr_t *addr)
#define tor_addr_to_in6_addr32(x)
static int tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
static bool tor_addr_is_unspec(const tor_addr_t *a)
void interface_address6_list_free_(struct smartlist_t *addrs)
void tor_addr_copy_tight(tor_addr_t *dest, const tor_addr_t *src)
int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa, uint16_t *port_out)
int tor_addr_is_internal_(const tor_addr_t *ip, int for_listening, const char *filename, int lineno)
int parse_port_range(const char *port, uint16_t *port_min_out, uint16_t *port_max_out)
char * tor_sockaddr_to_str(const struct sockaddr *sa)
int tor_addr_port_eq(const tor_addr_port_t *a, const tor_addr_port_t *b)
int tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2, maskbits_t mask, tor_addr_comparison_t how)
int tor_addr_to_PTR_name(char *out, size_t outlen, const tor_addr_t *addr)
tor_addr_port_t * tor_addr_port_new(const tor_addr_t *addr, uint16_t port)
Define in6_addr, its members, and related types on platforms that lack it.
Declarations for types used throughout the Tor networking system.
#define MOCK_DECL(rv, funcname, arglist)
Integer definitions used throughout Tor.
Macros to manage assertions, fatal and non-fatal.