2008-07-25 16:43:24 +02:00
|
|
|
/* Copyright (c) 2003-2004, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2016-02-27 18:48:19 +01:00
|
|
|
* Copyright (c) 2007-2016, The Tor Project, Inc. */
|
2008-07-25 16:43:24 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file address.h
|
|
|
|
* \brief Headers for address.h
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_ADDRESS_H
|
|
|
|
#define TOR_ADDRESS_H
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2014-05-24 14:03:14 +02:00
|
|
|
//#include <sys/sockio.h>
|
2008-07-25 16:43:24 +02:00
|
|
|
#include "orconfig.h"
|
|
|
|
#include "torint.h"
|
|
|
|
#include "compat.h"
|
2015-09-15 09:04:18 +02:00
|
|
|
#include "container.h"
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2014-05-24 14:03:14 +02:00
|
|
|
#ifdef ADDRESS_PRIVATE
|
|
|
|
|
|
|
|
#if defined(HAVE_SYS_IOCTL_H)
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GETIFADDRS
|
|
|
|
#define HAVE_IFADDRS_TO_SMARTLIST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define HAVE_IP_ADAPTER_TO_SMARTLIST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(SIOCGIFCONF) && defined(HAVE_IOCTL)
|
|
|
|
#define HAVE_IFCONF_TO_SMARTLIST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_NET_IF_H)
|
|
|
|
#include <net/if.h> // for struct ifconf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_IFADDRS_TO_SMARTLIST)
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO win32 specific includes
|
|
|
|
#endif // ADDRESS_PRIVATE
|
|
|
|
|
2008-12-22 18:53:04 +01:00
|
|
|
/** The number of bits from an address to consider while doing a masked
|
|
|
|
* comparison. */
|
2008-07-25 16:43:24 +02:00
|
|
|
typedef uint8_t maskbits_t;
|
2008-12-22 18:53:04 +01:00
|
|
|
|
2008-07-25 16:43:24 +02:00
|
|
|
struct in_addr;
|
|
|
|
/** Holds an IPv4 or IPv6 address. (Uses less memory than struct
|
|
|
|
* sockaddr_storage.) */
|
|
|
|
typedef struct tor_addr_t
|
|
|
|
{
|
|
|
|
sa_family_t family;
|
|
|
|
union {
|
2012-06-05 17:06:26 +02:00
|
|
|
uint32_t dummy_; /* This field is here so we have something to initialize
|
|
|
|
* with a reliable cross-platform type. */
|
2008-07-25 16:43:24 +02:00
|
|
|
struct in_addr in_addr;
|
|
|
|
struct in6_addr in6_addr;
|
|
|
|
} addr;
|
|
|
|
} tor_addr_t;
|
|
|
|
|
2011-11-24 18:29:56 +01:00
|
|
|
/** Holds an IP address and a TCP/UDP port. */
|
|
|
|
typedef struct tor_addr_port_t
|
|
|
|
{
|
|
|
|
tor_addr_t addr;
|
|
|
|
uint16_t port;
|
|
|
|
} tor_addr_port_t;
|
|
|
|
|
2012-08-31 23:02:19 +02:00
|
|
|
#define TOR_ADDR_NULL {AF_UNSPEC, {0}}
|
2012-03-27 15:00:34 +02:00
|
|
|
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a);
|
2016-06-12 23:47:14 +02:00
|
|
|
static inline const struct in6_addr *tor_addr_to_in6_assert(
|
|
|
|
const tor_addr_t *a);
|
2015-12-10 16:19:43 +01:00
|
|
|
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_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 int tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u);
|
2008-12-22 18:53:04 +01:00
|
|
|
|
2008-07-25 16:43:24 +02:00
|
|
|
socklen_t tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port,
|
2008-07-29 02:34:50 +02:00
|
|
|
struct sockaddr *sa_out, socklen_t len);
|
2008-08-07 21:13:35 +02:00
|
|
|
int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa,
|
|
|
|
uint16_t *port_out);
|
2008-08-05 22:08:19 +02:00
|
|
|
void tor_addr_make_unspec(tor_addr_t *a);
|
2012-11-01 01:50:56 +01:00
|
|
|
void tor_addr_make_null(tor_addr_t *a, sa_family_t family);
|
2011-05-02 22:43:11 +02:00
|
|
|
char *tor_sockaddr_to_str(const struct sockaddr *sa);
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return an in6_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
|
* an IPv6 address. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline const struct in6_addr *
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_to_in6(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
return a->family == AF_INET6 ? &a->addr.in6_addr : NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-12 23:47:14 +02:00
|
|
|
/** As tor_addr_to_in6, but assert that the address truly is an IPv6
|
|
|
|
* address. */
|
2016-05-30 17:12:58 +02:00
|
|
|
static inline const struct in6_addr *
|
|
|
|
tor_addr_to_in6_assert(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
tor_assert(a->family == AF_INET6);
|
|
|
|
return &a->addr.in6_addr;
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Given an IPv6 address <b>x</b>, yield it as an array of uint8_t.
|
|
|
|
*
|
|
|
|
* Requires that <b>x</b> is actually an IPv6 address.
|
|
|
|
*/
|
2016-05-30 17:12:58 +02:00
|
|
|
#define tor_addr_to_in6_addr8(x) tor_addr_to_in6_assert(x)->s6_addr
|
|
|
|
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Given an IPv6 address <b>x</b>, yield it as an array of uint16_t.
|
|
|
|
*
|
|
|
|
* Requires that <b>x</b> is actually an IPv6 address.
|
|
|
|
*/
|
2016-05-30 17:12:58 +02:00
|
|
|
#define tor_addr_to_in6_addr16(x) S6_ADDR16(*tor_addr_to_in6_assert(x))
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Given an IPv6 address <b>x</b>, yield it as an array of uint32_t.
|
|
|
|
*
|
|
|
|
* Requires that <b>x</b> is actually an IPv6 address.
|
|
|
|
*/
|
2016-05-30 17:12:58 +02:00
|
|
|
#define tor_addr_to_in6_addr32(x) S6_ADDR32(*tor_addr_to_in6_assert(x))
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return an IPv4 address in network order for <b>a</b>, or 0 if
|
|
|
|
* <b>a</b> is not an IPv4 address. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline uint32_t
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_to_ipv4n(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
return a->family == AF_INET ? a->addr.in_addr.s_addr : 0;
|
|
|
|
}
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return an IPv4 address in host order for <b>a</b>, or 0 if
|
|
|
|
* <b>a</b> is not an IPv4 address. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline uint32_t
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_to_ipv4h(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
return ntohl(tor_addr_to_ipv4n(a));
|
|
|
|
}
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Given an IPv6 address, return its mapped IPv4 address in host order, or
|
2008-12-25 16:37:47 +01:00
|
|
|
* 0 if <b>a</b> is not an IPv6 address.
|
|
|
|
*
|
|
|
|
* (Does not check whether the address is really a mapped address */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline uint32_t
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_to_mapped_ipv4h(const tor_addr_t *a)
|
|
|
|
{
|
2014-09-15 19:52:13 +02:00
|
|
|
if (a->family == AF_INET6) {
|
|
|
|
uint32_t *addr32 = NULL;
|
|
|
|
// Work around an incorrect NULL pointer dereference warning in
|
|
|
|
// "clang --analyze" due to limited analysis depth
|
|
|
|
addr32 = tor_addr_to_in6_addr32(a);
|
|
|
|
// To improve performance, wrap this assertion in:
|
|
|
|
// #if !defined(__clang_analyzer__) || PARANOIA
|
|
|
|
tor_assert(addr32);
|
|
|
|
return ntohl(addr32[3]);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-25 16:43:24 +02:00
|
|
|
}
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return the address family of <b>a</b>. Possible values are:
|
|
|
|
* AF_INET6, AF_INET, AF_UNSPEC. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline sa_family_t
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_family(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
return a->family;
|
|
|
|
}
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return an in_addr* equivalent to <b>a</b>, or NULL if <b>a</b> is not
|
|
|
|
* an IPv4 address. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline const struct in_addr *
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_to_in(const tor_addr_t *a)
|
|
|
|
{
|
|
|
|
return a->family == AF_INET ? &a->addr.in_addr : NULL;
|
|
|
|
}
|
2008-12-25 16:37:47 +01:00
|
|
|
/** Return true iff <b>a</b> is an IPv4 address equal to the host-ordered
|
|
|
|
* address in <b>u</b>. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline int
|
2008-07-29 02:34:50 +02:00
|
|
|
tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
|
|
|
|
{
|
|
|
|
return a->family == AF_INET ? (tor_addr_to_ipv4h(a) == u) : 0;
|
|
|
|
}
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Length of a buffer that you need to allocate to be sure you can encode
|
|
|
|
* any tor_addr_t.
|
|
|
|
*
|
|
|
|
* This allows enough space for
|
|
|
|
* "[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]",
|
|
|
|
* plus a terminating NUL.
|
|
|
|
*/
|
|
|
|
#define TOR_ADDR_BUF_LEN 48
|
2008-07-25 16:43:24 +02:00
|
|
|
|
|
|
|
int tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out);
|
2016-03-28 22:36:51 +02:00
|
|
|
char *tor_addr_to_str_dup(const tor_addr_t *addr) ATTR_MALLOC;
|
2012-04-12 22:42:37 +02:00
|
|
|
|
|
|
|
/** Wrapper function of fmt_addr_impl(). It does not decorate IPv6
|
|
|
|
* addresses. */
|
|
|
|
#define fmt_addr(a) fmt_addr_impl((a), 0)
|
|
|
|
/** Wrapper function of fmt_addr_impl(). It decorates IPv6
|
|
|
|
* addresses. */
|
|
|
|
#define fmt_and_decorate_addr(a) fmt_addr_impl((a), 1)
|
2012-03-31 13:48:20 +02:00
|
|
|
const char *fmt_addr_impl(const tor_addr_t *addr, int decorate);
|
2012-10-05 04:43:44 +02:00
|
|
|
const char *fmt_addrport(const tor_addr_t *addr, uint16_t port);
|
2010-10-02 03:31:09 +02:00
|
|
|
const char * fmt_addr32(uint32_t addr);
|
2015-09-15 09:04:18 +02:00
|
|
|
|
2014-04-28 22:20:58 +02:00
|
|
|
MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family,
|
|
|
|
tor_addr_t *addr));
|
2015-09-15 09:04:18 +02:00
|
|
|
void free_interface_address6_list(smartlist_t * addrs);
|
|
|
|
MOCK_DECL(smartlist_t *,get_interface_address6_list,(int severity,
|
|
|
|
sa_family_t family,
|
|
|
|
int include_internal));
|
2008-07-25 17:11:21 +02:00
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
/** 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. */
|
2008-07-25 17:11:21 +02:00
|
|
|
typedef enum {
|
|
|
|
CMP_EXACT,
|
|
|
|
CMP_SEMANTIC,
|
|
|
|
} tor_addr_comparison_t;
|
|
|
|
|
|
|
|
int tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2,
|
|
|
|
tor_addr_comparison_t how);
|
2008-07-25 16:43:24 +02:00
|
|
|
int tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
|
2008-07-25 17:11:21 +02:00
|
|
|
maskbits_t mask, tor_addr_comparison_t how);
|
2008-08-05 22:08:19 +02:00
|
|
|
/** 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))
|
2008-07-25 17:11:21 +02:00
|
|
|
|
2014-02-07 23:38:16 +01:00
|
|
|
uint64_t tor_addr_hash(const tor_addr_t *addr);
|
2008-07-25 16:43:24 +02:00
|
|
|
int tor_addr_is_v4(const tor_addr_t *addr);
|
2012-10-12 17:34:54 +02:00
|
|
|
int tor_addr_is_internal_(const tor_addr_t *ip, int for_listening,
|
|
|
|
const char *filename, int lineno);
|
|
|
|
#define tor_addr_is_internal(addr, for_listening) \
|
2012-10-12 18:22:13 +02:00
|
|
|
tor_addr_is_internal_((addr), (for_listening), SHORT_FILE__, __LINE__)
|
2015-12-07 04:44:23 +01:00
|
|
|
int tor_addr_is_multicast(const tor_addr_t *a);
|
2008-12-19 19:52:00 +01:00
|
|
|
|
|
|
|
/** Longest length that can be required for a reverse lookup name. */
|
|
|
|
/* 32 nybbles, 32 dots, 8 characters of "ip6.arpa", 1 NUL: 73 characters. */
|
|
|
|
#define REVERSE_LOOKUP_NAME_BUF_LEN 73
|
2011-10-11 17:47:13 +02:00
|
|
|
int tor_addr_to_PTR_name(char *out, size_t outlen,
|
2008-12-19 19:52:00 +01:00
|
|
|
const tor_addr_t *addr);
|
2011-10-11 17:47:13 +02:00
|
|
|
int tor_addr_parse_PTR_name(tor_addr_t *result, const char *address,
|
2008-12-19 19:52:00 +01:00
|
|
|
int family, int accept_regular);
|
|
|
|
|
2011-10-11 17:21:31 +02:00
|
|
|
int tor_addr_port_lookup(const char *s, tor_addr_t *addr_out,
|
2008-08-05 22:08:19 +02:00
|
|
|
uint16_t *port_out);
|
2015-09-14 03:46:58 +02:00
|
|
|
|
|
|
|
/* Does the address * yield an AF_UNSPEC wildcard address (1),
|
|
|
|
* which expands to corresponding wildcard IPv4 and IPv6 rules, and do we
|
2015-09-09 15:48:33 +02:00
|
|
|
* allow *4 and *6 for IPv4 and IPv6 wildcards, respectively;
|
|
|
|
* or does the address * yield IPv4 wildcard address (0). */
|
2012-10-24 18:33:18 +02:00
|
|
|
#define TAPMP_EXTENDED_STAR 1
|
2015-09-14 03:46:58 +02:00
|
|
|
/* Does the address * yield an IPv4 wildcard address rule (1);
|
|
|
|
* or does it yield wildcard IPv4 and IPv6 rules (0) */
|
|
|
|
#define TAPMP_STAR_IPV4_ONLY (1 << 1)
|
|
|
|
/* Does the address * yield an IPv6 wildcard address rule (1);
|
|
|
|
* or does it yield wildcard IPv4 and IPv6 rules (0) */
|
|
|
|
#define TAPMP_STAR_IPV6_ONLY (1 << 2)
|
|
|
|
/* TAPMP_STAR_IPV4_ONLY and TAPMP_STAR_IPV6_ONLY are mutually exclusive. */
|
2012-10-24 18:33:18 +02:00
|
|
|
int tor_addr_parse_mask_ports(const char *s, unsigned flags,
|
2008-07-25 16:43:24 +02:00
|
|
|
tor_addr_t *addr_out, maskbits_t *mask_out,
|
|
|
|
uint16_t *port_min_out, uint16_t *port_max_out);
|
2010-10-07 06:31:08 +02:00
|
|
|
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len,
|
2008-07-25 16:43:24 +02:00
|
|
|
int decorate);
|
2011-10-11 17:21:31 +02:00
|
|
|
int tor_addr_parse(tor_addr_t *addr, const char *src);
|
2008-07-25 16:43:24 +02:00
|
|
|
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src);
|
2014-02-07 23:38:16 +01:00
|
|
|
void tor_addr_copy_tight(tor_addr_t *dest, const tor_addr_t *src);
|
2008-08-05 22:08:19 +02:00
|
|
|
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))
|
2008-08-08 14:58:17 +02:00
|
|
|
void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const char *bytes);
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Set <b>dest</b> to the IPv4 address incoded in <b>in</b>. */
|
2008-12-26 22:26:05 +01:00
|
|
|
#define tor_addr_from_in(dest, in) \
|
|
|
|
tor_addr_from_ipv4n((dest), (in)->s_addr);
|
2008-08-08 14:58:17 +02:00
|
|
|
void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6);
|
2008-07-25 16:43:24 +02:00
|
|
|
int tor_addr_is_null(const tor_addr_t *addr);
|
|
|
|
int tor_addr_is_loopback(const tor_addr_t *addr);
|
|
|
|
|
2015-12-22 00:42:09 +01:00
|
|
|
int tor_addr_is_valid(const tor_addr_t *addr, int for_listening);
|
|
|
|
int tor_addr_is_valid_ipv4n(uint32_t v4n_addr, int for_listening);
|
|
|
|
#define tor_addr_is_valid_ipv4h(v4h_addr, for_listening) \
|
|
|
|
tor_addr_is_valid_ipv4n(htonl(v4h_addr), (for_listening))
|
|
|
|
int tor_port_is_valid(uint16_t port, int for_listening);
|
|
|
|
/* Are addr and port both valid? */
|
|
|
|
#define tor_addr_port_is_valid(addr, port, for_listening) \
|
|
|
|
(tor_addr_is_valid((addr), (for_listening)) && \
|
|
|
|
tor_port_is_valid((port), (for_listening)))
|
|
|
|
/* Are ap->addr and ap->port both valid? */
|
|
|
|
#define tor_addr_port_is_valid_ap(ap, for_listening) \
|
|
|
|
tor_addr_port_is_valid(&(ap)->addr, (ap)->port, (for_listening))
|
|
|
|
/* Are the network-order v4addr and port both valid? */
|
|
|
|
#define tor_addr_port_is_valid_ipv4n(v4n_addr, port, for_listening) \
|
|
|
|
(tor_addr_is_valid_ipv4n((v4n_addr), (for_listening)) && \
|
|
|
|
tor_port_is_valid((port), (for_listening)))
|
|
|
|
/* Are the host-order v4addr and port both valid? */
|
|
|
|
#define tor_addr_port_is_valid_ipv4h(v4h_addr, port, for_listening) \
|
|
|
|
(tor_addr_is_valid_ipv4h((v4h_addr), (for_listening)) && \
|
|
|
|
tor_port_is_valid((port), (for_listening)))
|
|
|
|
|
2011-10-11 18:02:19 +02:00
|
|
|
int tor_addr_port_split(int severity, const char *addrport,
|
|
|
|
char **address_out, uint16_t *port_out);
|
|
|
|
|
2012-11-27 23:24:58 +01:00
|
|
|
int tor_addr_port_parse(int severity, const char *addrport,
|
2014-03-27 20:31:29 +01:00
|
|
|
tor_addr_t *address_out, uint16_t *port_out,
|
|
|
|
int default_port);
|
2012-11-27 23:24:58 +01:00
|
|
|
|
2012-03-28 09:19:00 +02:00
|
|
|
int tor_addr_hostname_is_local(const char *name);
|
|
|
|
|
2008-07-25 16:43:24 +02:00
|
|
|
/* IPv4 helpers */
|
2011-10-11 17:21:31 +02:00
|
|
|
int addr_port_lookup(int severity, const char *addrport, char **address,
|
2008-07-25 16:43:24 +02:00
|
|
|
uint32_t *addr, uint16_t *port_out);
|
|
|
|
int parse_port_range(const char *port, uint16_t *port_min_out,
|
|
|
|
uint16_t *port_max_out);
|
|
|
|
int addr_mask_get_bits(uint32_t mask);
|
2008-12-22 15:56:28 +01:00
|
|
|
/** Length of a buffer to allocate to hold the results of tor_inet_ntoa.*/
|
|
|
|
#define INET_NTOA_BUF_LEN 16
|
2008-07-25 16:43:24 +02:00
|
|
|
int tor_inet_ntoa(const struct in_addr *in, char *buf, size_t buf_len);
|
|
|
|
char *tor_dup_ip(uint32_t addr) ATTR_MALLOC;
|
2014-04-28 22:20:58 +02:00
|
|
|
MOCK_DECL(int,get_interface_address,(int severity, uint32_t *addr));
|
2015-09-15 09:04:18 +02:00
|
|
|
/** Free a smartlist of IP addresses returned by get_interface_address_list.
|
|
|
|
*/
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline void
|
2015-09-15 09:04:18 +02:00
|
|
|
free_interface_address_list(smartlist_t *addrs)
|
|
|
|
{
|
|
|
|
free_interface_address6_list(addrs);
|
|
|
|
}
|
|
|
|
/** Return a smartlist of the IPv4 addresses of all interfaces on the server.
|
|
|
|
* Excludes loopback and multicast addresses. Only includes internal addresses
|
|
|
|
* if include_internal is true. (Note that a relay behind NAT may use an
|
|
|
|
* internal address to connect to the Internet.)
|
|
|
|
* An empty smartlist means that there are no IPv4 addresses.
|
|
|
|
* Returns NULL on failure.
|
|
|
|
* Use free_interface_address_list to free the returned list.
|
|
|
|
*/
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline smartlist_t *
|
2015-09-15 09:04:18 +02:00
|
|
|
get_interface_address_list(int severity, int include_internal)
|
|
|
|
{
|
|
|
|
return get_interface_address6_list(severity, AF_INET, include_internal);
|
|
|
|
}
|
2008-07-25 16:43:24 +02:00
|
|
|
|
2012-08-31 23:02:19 +02:00
|
|
|
tor_addr_port_t *tor_addr_port_new(const tor_addr_t *addr, uint16_t port);
|
|
|
|
|
2014-05-24 14:03:14 +02:00
|
|
|
#ifdef ADDRESS_PRIVATE
|
2016-01-03 15:35:45 +01:00
|
|
|
MOCK_DECL(smartlist_t *,get_interface_addresses_raw,(int severity,
|
|
|
|
sa_family_t family));
|
2015-09-29 07:04:49 +02:00
|
|
|
MOCK_DECL(int,get_interface_address6_via_udp_socket_hack,(int severity,
|
|
|
|
sa_family_t family,
|
|
|
|
tor_addr_t *addr));
|
2014-05-24 14:03:14 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_IFADDRS_TO_SMARTLIST
|
2016-01-03 15:35:45 +01:00
|
|
|
STATIC smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa,
|
|
|
|
sa_family_t family);
|
|
|
|
STATIC smartlist_t *get_interface_addresses_ifaddrs(int severity,
|
|
|
|
sa_family_t family);
|
2014-05-24 14:03:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IP_ADAPTER_TO_SMARTLIST
|
|
|
|
STATIC smartlist_t *ip_adapter_addresses_to_smartlist(
|
|
|
|
const IP_ADAPTER_ADDRESSES *addresses);
|
2016-01-03 15:35:45 +01:00
|
|
|
STATIC smartlist_t *get_interface_addresses_win32(int severity,
|
|
|
|
sa_family_t family);
|
2014-05-24 14:03:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IFCONF_TO_SMARTLIST
|
2015-02-12 13:59:31 +01:00
|
|
|
STATIC smartlist_t *ifreq_to_smartlist(char *ifr,
|
2014-05-24 14:03:14 +02:00
|
|
|
size_t buflen);
|
2016-01-03 15:35:45 +01:00
|
|
|
STATIC smartlist_t *get_interface_addresses_ioctl(int severity,
|
|
|
|
sa_family_t family);
|
2014-05-24 14:03:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // ADDRESS_PRIVATE
|
|
|
|
|
2008-07-25 16:43:24 +02:00
|
|
|
#endif
|
|
|
|
|