#include "orconfig.h"
#include "torint.h"
#include "compat.h"
Go to the source code of this file.
Data Structures | |
struct | tor_addr_t |
Defines | |
#define | tor_addr_to_in6_addr8(x) tor_addr_to_in6(x)->s6_addr |
#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)) |
#define | TOR_ADDR_BUF_LEN 48 |
#define | tor_addr_eq(a, b) (0==tor_addr_compare((a),(b),CMP_EXACT)) |
#define | REVERSE_LOOKUP_NAME_BUF_LEN 73 |
#define | tor_addr_from_ipv4h(dest, v4addr) tor_addr_from_ipv4n((dest), htonl(v4addr)) |
#define | tor_addr_from_in(dest, in) tor_addr_from_ipv4n((dest), (in)->s_addr); |
#define | INET_NTOA_BUF_LEN 16 |
Typedefs | |
typedef uint8_t | maskbits_t |
Enumerations | |
enum | tor_addr_comparison_t { CMP_EXACT, CMP_SEMANTIC } |
Functions | |
static INLINE 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) |
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 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) |
socklen_t | tor_addr_to_sockaddr (const tor_addr_t *a, uint16_t port, struct sockaddr *sa_out, socklen_t len) |
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) |
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) |
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) |
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_to_reverse_lookup_name (char *out, size_t outlen, const tor_addr_t *addr) |
int | tor_addr_parse_reverse_lookup_name (tor_addr_t *result, const char *address, int family, int accept_regular) |
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) |
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_ipv4n (tor_addr_t *dest, uint32_t v4addr) |
void | tor_addr_from_ipv6_bytes (tor_addr_t *dest, const char *bytes) |
void | tor_addr_from_in6 (tor_addr_t *dest, const struct in6_addr *in6) |
int | tor_addr_is_null (const tor_addr_t *addr) |
int | tor_addr_is_loopback (const tor_addr_t *addr) |
int | is_internal_IP (uint32_t ip, int for_listening) ATTR_PURE |
int | parse_addr_port (int severity, const char *addrport, char **address, 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 | parse_addr_and_port_range (const char *s, uint32_t *addr_out, maskbits_t *maskbits_out, uint16_t *port_min_out, uint16_t *port_max_out) |
int | addr_mask_get_bits (uint32_t mask) |
int | addr_mask_cmp_bits (uint32_t a1, uint32_t a2, maskbits_t bits) |
int | tor_inet_ntoa (const struct in_addr *in, char *buf, size_t buf_len) |
char * | tor_dup_ip (uint32_t addr) ATTR_MALLOC |
int | get_interface_address (int severity, uint32_t *addr) |
#define INET_NTOA_BUF_LEN 16 |
Length of a buffer to allocate to hold the results of tor_inet_ntoa.
Referenced by client_dns_set_addressmap(), client_dns_set_addressmap_impl(), connection_edge_process_relay_cell_not_open(), directory_initiate_command_routerstatus_rend(), evdns_callback(), evdns_wildcard_check_callback(), format_networkstatus_vote(), generate_v2_networkstatus_opinion(), log_addr_has_changed(), networkstatus_compute_consensus(), resolve_my_address(), routerstatus_format_entry(), tell_controller_about_resolved_result(), and tor_addr_parse_reverse_lookup_name().
#define REVERSE_LOOKUP_NAME_BUF_LEN 73 |
Longest length that can be required for a reverse lookup name.
Referenced by connection_ap_handshake_send_resolve(), and tor_addr_to_reverse_lookup_name().
#define tor_addr_eq | ( | a, | |||
b | ) | (0==tor_addr_compare((a),(b),CMP_EXACT)) |
Return true iff a and b are the same address. The comparison is done "exactly".
Referenced by circuit_dump_by_conn(), circuit_get_all_pending_on_or_conn(), circuit_is_acceptable(), circuit_n_conn_done(), command_process_netinfo_cell(), connection_ap_fail_onehop(), and connection_get_by_type_addr_port_purpose().
#define tor_addr_from_ipv4h | ( | dest, | |||
v4addr | ) | tor_addr_from_ipv4n((dest), htonl(v4addr)) |
Set dest to the IPv4 address encoded in v4addr in host order.
Referenced by addr_policy_permits_address(), circuit_extend(), compare_addr_to_addr_policy(), connection_or_init_conn_from_address(), connection_or_send_netinfo(), consider_testing_reachability(), directory_get_from_dirserver(), directory_initiate_command_routerstatus_rend(), directory_post_to_dirservers(), dirserv_single_reachability_test(), dns_found_answer(), dns_resolve_impl(), exit_policy_is_general_exit_helper(), extend_info_from_router(), fascist_firewall_allows_or(), parse_port_config(), router_find_exact_exit_enclave(), router_pick_directory_server_impl(), router_pick_trusteddirserver_impl(), routerset_contains_router(), routerset_contains_routerstatus(), tor_addr_parse_mask_ports(), and update_v2_networkstatus_cache_downloads().
typedef uint8_t maskbits_t |
The number of bits from an address to consider while doing a masked comparison.
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.
int addr_mask_cmp_bits | ( | uint32_t | a1, | |
uint32_t | a2, | |||
maskbits_t | bits | |||
) |
Compare two addresses a1 and a2 for equality under a netmask of mbits bits. Return -1, 0, or 1.
XXXX_IP6 Temporary function to allow masks as bitcounts everywhere. This will be replaced with an IPv6-aware version as soon as 32-bit addresses are no longer passed around.
Referenced by address_is_in_virtual_range(), addressmap_get_virtual_address(), and parse_virtual_addr_network().
int addr_mask_get_bits | ( | uint32_t | mask | ) |
If mask is an address mask for a bit-prefix, return the number of bits. Otherwise, return -1.
Referenced by parse_addr_and_port_range(), and tor_addr_parse_mask_ports().
const char* fmt_addr | ( | const tor_addr_t * | addr | ) |
Return a string representing the address addr. This string is statically allocated, and must not be freed. Each call to fmt_addr invalidates the last result of the function. This function is not thread-safe.
References tor_addr_to_str().
Referenced by circuit_extend(), circuit_handle_first_hop(), connection_edge_finished_connecting(), connection_handle_listener_read(), connection_proxy_connect(), fetch_bridge_descriptors(), parse_bridge_line(), and rend_add_service().
int get_interface_address | ( | int | severity, | |
uint32_t * | addr | |||
) |
Set *addr to the host-order IPv4 address (if any) of whatever interface connects to the Internet. This address should only be used in checking whether our address has changed. Return 0 on success, -1 on failure.
References get_interface_address6(), and tor_addr_to_ipv4h().
Referenced by client_check_address_changed(), and resolve_my_address().
int get_interface_address6 | ( | int | severity, | |
sa_family_t | family, | |||
tor_addr_t * | addr | |||
) |
Set *addr to the IP address (if any) of whatever interface connects to the Internet. This address should only be used in checking whether our address has changed. Return 0 on success, -1 on failure.
References LD_NET, tor_addr_from_sockaddr(), tor_assert, tor_close_socket(), and tor_open_socket().
Referenced by get_interface_address().
int is_internal_IP | ( | uint32_t | ip, | |
int | for_listening | |||
) |
Return true iff ip (in host order) is an IP reserved to localhost, or reserved for local networks by RFC 1918.
References tor_addr_t::addr, tor_addr_t::family, tor_addr_t::in_addr, and tor_addr_is_internal().
Referenced by connection_ap_process_end_not_open(), connection_edge_process_relay_cell_not_open(), dirserv_router_has_valid_address(), http_set_address_origin(), options_validate(), resolve_my_address(), and router_new_address_suggestion().
int parse_addr_and_port_range | ( | const char * | s, | |
uint32_t * | addr_out, | |||
maskbits_t * | maskbits_out, | |||
uint16_t * | port_min_out, | |||
uint16_t * | port_max_out | |||
) |
Parse a string s in the format of (IP(/mask|/mask-bits)?|*)(:(*|port(-maxport))?)?, setting the various *out pointers as appropriate. Return 0 on success, -1 on failure.
References addr_mask_get_bits(), escaped(), LD_GENERAL, parse_port_range(), tor_assert, tor_free, and tor_inet_aton().
Referenced by parse_virtual_addr_network().
int parse_addr_port | ( | int | severity, | |
const char * | addrport, | |||
char ** | address, | |||
uint32_t * | addr, | |||
uint16_t * | port_out | |||
) |
Parse a string of the form "host[:port]" from addrport. If address is provided, set *address to a copy of the host portion of the string. If addr is provided, try to resolve the host portion of the string and store it into *addr (in host byte order). If port_out is provided, store the port number into *port_out, or 0 if no port is given. If port_out is NULL, then there must be no port number in addrport. Return 0 on success, -1 on failure.
References esc_for_log(), escaped(), LD_GENERAL, LD_NET, tor_assert, tor_free, tor_lookup_hostname(), and tor_parse_long().
Referenced by authority_cert_parse_from_string(), connection_exit_begin_conn(), create_inet_sockaddr(), options_validate(), parse_dir_server_line(), and retry_listeners().
int parse_port_range | ( | const char * | port, | |
uint16_t * | port_min_out, | |||
uint16_t * | port_max_out | |||
) |
Parse a string s in the format of (*|port(-maxport)?)?, setting the various *out pointers as appropriate. Return 0 on success, -1 on failure.
References escaped(), LD_GENERAL, tor_assert, and tor_parse_long().
Referenced by parse_addr_and_port_range(), router_parse_addr_policy_private(), and tor_addr_parse_mask_ports().
int tor_addr_compare | ( | const tor_addr_t * | addr1, | |
const tor_addr_t * | addr2, | |||
tor_addr_comparison_t | how | |||
) |
Given two addresses addr1 and addr2, return 0 if the two addresses are equivalent under the mask mbits, less than 0 if addr1 precedes addr2, and greater than 0 otherwise.
Different address families (IPv4 vs IPv6) are always considered unequal if how is CMP_EXACT; otherwise, IPv6-mapped IPv4 addresses are considered equivalent to their IPv4 equivalents.
References tor_addr_compare_masked().
Referenced by cmp_single_addr_policy(), connection_or_get_for_extend(), connection_or_group_set_badness(), and policy_summary_add_item().
int tor_addr_compare_masked | ( | const tor_addr_t * | addr1, | |
const tor_addr_t * | addr2, | |||
maskbits_t | mbits, | |||
tor_addr_comparison_t | how | |||
) |
As tor_addr_compare(), but only looks at the first mask bits of the address.
Reduce over-specific masks (>128 for ipv6, >32 for ipv4) to 128 or 32.
The mask is interpreted relative to addr1, so that if a is ffff:1.2.3.4, and b is 3.4.5.6, tor_addr_compare_masked(a,b,100,CMP_SEMANTIC) is the same as -tor_addr_compare_masked(b,a,4,CMP_SEMANTIC).
We guarantee that the ordering from tor_addr_compare_masked is a total order on addresses, but not that it is any particular order, or that it will be the same from one version to the next.
References tor_addr_family(), tor_addr_is_v4(), tor_addr_to_ipv4h(), tor_assert, and tor_fragile_assert.
Referenced by addr_policy_covers(), addr_policy_intersects(), compare_known_tor_addr_to_addr_policy(), compare_known_tor_addr_to_addr_policy_noport(), and tor_addr_compare().
void tor_addr_copy | ( | tor_addr_t * | dest, | |
const tor_addr_t * | src | |||
) |
Copy a tor_addr_t from src to dest.
References tor_assert.
Referenced by bridge_add_from_config(), connection_exit_begin_conn(), connection_exit_connect_dir(), connection_handle_listener_read(), connection_or_connect(), connection_or_init_conn_from_address(), directory_initiate_command_rend(), dns_resolve_impl(), evdns_server_callback(), extend_info_alloc(), parse_port_config(), and tor_addr_port_parse().
static INLINE int tor_addr_eq_ipv4h | ( | const tor_addr_t * | a, | |
uint32_t | u | |||
) | [static] |
Return true iff a is an IPv4 address equal to the host-ordered address in u.
References tor_addr_t::family, and tor_addr_to_ipv4h().
Referenced by connection_or_init_conn_from_address(), directory_conn_is_self_reachability_test(), directory_handle_command_get(), router_new_address_suggestion(), and routerinfo_get_configured_bridge().
static INLINE sa_family_t tor_addr_family | ( | const tor_addr_t * | a | ) | [static] |
Return the address family of a. Possible values are: AF_INET6, AF_INET, AF_UNSPEC.
References tor_addr_t::family.
Referenced by append_address_to_payload(), circuit_send_next_onion_skin(), connection_connect(), connection_edge_end(), connection_edge_finished_connecting(), connection_exit_connect(), connection_is_rate_limited(), connection_or_set_state_open(), connection_proxy_connect(), connection_send_socks5_connect(), dns_resolve_impl(), is_local_addr(), launch_resolve(), policy_write_item(), rend_parse_introduction_points(), router_add_exit_policy(), router_compare_to_my_exit_policy(), tor_addr_compare_masked(), tor_addr_hash(), tor_addr_is_internal(), tor_addr_is_loopback(), tor_addr_is_null(), tor_addr_is_v4(), tor_addr_parse_mask_ports(), tor_addr_to_sockaddr(), tor_addr_to_str(), and tor_lookup_hostname().
void tor_addr_from_in6 | ( | tor_addr_t * | dest, | |
const struct in6_addr * | in6 | |||
) |
Set dest equal to the IPv6 address in the in6_addr in6.
References tor_addr_from_ipv6_bytes().
Referenced by connection_ap_get_original_destination(), tor_addr_from_sockaddr(), tor_addr_from_str(), tor_addr_lookup(), tor_addr_parse_mask_ports(), and tor_addr_parse_reverse_lookup_name().
void tor_addr_from_ipv4n | ( | tor_addr_t * | dest, | |
uint32_t | v4addr | |||
) |
Set dest to equal the IPv4 address in v4addr (given in network order).
References tor_addr_t::addr, tor_addr_t::family, tor_addr_t::in_addr, and tor_assert.
Referenced by connection_ap_get_original_destination(), decode_address_from_payload(), fetch_from_buf_socks(), rend_service_introduce(), and tor_addr_from_sockaddr().
void tor_addr_from_ipv6_bytes | ( | tor_addr_t * | dest, | |
const char * | ipv6_bytes | |||
) |
Set dest to equal the IPv6 address in the 16 bytes at ipv6_bytes.
References tor_addr_t::addr, tor_addr_t::family, tor_addr_t::in6_addr, and tor_assert.
Referenced by decode_address_from_payload(), fetch_from_buf_socks(), and tor_addr_from_in6().
int tor_addr_from_sockaddr | ( | tor_addr_t * | a, | |
const struct sockaddr * | sa, | |||
uint16_t * | port_out | |||
) |
Set the tor_addr_t in a to contain the socket address contained in sa.
References tor_addr_from_in6(), tor_addr_from_ipv4n(), tor_addr_make_unspec(), and tor_assert.
Referenced by connection_ap_get_original_destination(), connection_handle_listener_read(), evdns_server_callback(), and get_interface_address6().
int tor_addr_from_str | ( | tor_addr_t * | addr, | |
const char * | src | |||
) |
Convert the string in src to a tor_addr_t addr. The string may be an IPv4 address, an IPv6 address, or an IPv6 address surrounded by square brackets.
Return an address family on success, or -1 if an invalid address string is provided.
References tor_addr_from_in6(), tor_assert, tor_free, and tor_inet_pton().
Referenced by circuit_get_open_circ_or_launch(), circuit_is_acceptable(), configure_nameservers(), connection_ap_fail_onehop(), dns_resolve_impl(), rend_parse_introduction_points(), and tor_addr_parse_reverse_lookup_name().
unsigned int tor_addr_hash | ( | const tor_addr_t * | addr | ) |
Return a hash code based on the address addr
References tor_addr_family(), tor_addr_to_ipv4h(), and tor_fragile_assert.
Referenced by policy_hash().
int tor_addr_is_internal | ( | const tor_addr_t * | addr, | |
int | for_listening | |||
) |
Return true iff ip is an IP reserved to localhost or local networks in RFC1918 or RFC4193 or RFC4291. (fec0::/10, deprecated by RFC3879, is also treated as internal for now.)
References LD_BUG, tor_addr_family(), tor_addr_is_v4(), and tor_addr_to_ipv4h().
Referenced by connection_is_rate_limited(), dns_resolve_impl(), exit_policy_is_general_exit_helper(), is_internal_IP(), and is_local_addr().
int tor_addr_is_loopback | ( | const tor_addr_t * | addr | ) |
Return true iff addr is a loopback address
References tor_addr_family(), tor_addr_to_ipv4h(), tor_assert, and tor_fragile_assert.
Referenced by connection_connect().
int tor_addr_is_null | ( | const tor_addr_t * | addr | ) |
Determine whether an address addr is null, either all zeroes or belonging to family AF_UNSPEC.
References LD_BUG, tor_addr_family(), tor_addr_to_ipv4n(), and tor_assert.
Referenced by compare_tor_addr_to_addr_policy(), connection_ap_expire_beginning(), connection_ap_handshake_attach_circuit(), connection_exit_begin_conn(), and router_compare_to_my_exit_policy().
int tor_addr_is_v4 | ( | const tor_addr_t * | addr | ) |
Determine whether an address is IPv4, either native or IPv4-mapped IPv6. Note that this is about representation only, as any decent stack will reject IPv4-mapped addresses received on the wire (and won't use them on the wire either).
References tor_addr_family(), and tor_assert.
Referenced by tor_addr_compare_masked(), tor_addr_is_internal(), and tor_addr_parse_mask_ports().
int tor_addr_lookup | ( | const char * | name, | |
uint16_t | family, | |||
tor_addr_t * | addr | |||
) |
Similar behavior to Unix gethostbyname: resolve name, and set *addr to the proper IP address and family. The family argument (which must be AF_INET, AF_INET6, or AF_UNSPEC) declares a preferred family, though another one may be returned if only one family is implemented for this address.
Return 0 on success, -1 on failure; 1 on transient failure.
References tor_addr_from_in6(), tor_assert, and tor_inet_pton().
Referenced by tor_addr_port_parse(), and tor_lookup_hostname().
void tor_addr_make_unspec | ( | tor_addr_t * | a | ) |
Set address a to the unspecified address. This address belongs to no family.
References tor_addr_t::family.
Referenced by connection_ap_make_link(), connection_handle_listener_read(), decode_address_from_payload(), and tor_addr_from_sockaddr().
int tor_addr_parse_mask_ports | ( | const char * | s, | |
tor_addr_t * | addr_out, | |||
maskbits_t * | maskbits_out, | |||
uint16_t * | port_min_out, | |||
uint16_t * | port_max_out | |||
) |
Parse a string s containing an IPv4/IPv6 address, and possibly a mask and port or port range. Store the parsed address in addr_out, a mask (if any) in mask_out, and port(s) (if any) in port_min_out and port_max_out.
The syntax is: Address OptMask OptPortRange Address ::= IPv4Address / "[" IPv6Address "]" / "*" OptMask ::= "/" Integer / OptPortRange ::= ":*" / ":" Integer / ":" Integer "-" Integer /
Return an address family on success, or -1 if an invalid address string is provided.
References addr_mask_get_bits(), escaped(), LD_GENERAL, parse_port_range(), tor_addr_family(), tor_addr_from_in6(), tor_addr_from_ipv4h, tor_addr_is_v4(), tor_assert, tor_free, and tor_inet_pton().
Referenced by policy_expand_private(), policy_summary_add_item(), and router_parse_addr_policy().
int tor_addr_parse_reverse_lookup_name | ( | tor_addr_t * | result, | |
const char * | address, | |||
int | family, | |||
int | accept_regular | |||
) |
Parse an .in-addr.arpa or .ip6.arpa address from address. Return 0 if this is not an .in-addr.arpa address or an .ip6.arpa address. Return -1 if this is an ill-formed .in-addr.arpa address or an .ip6.arpa address. Also return -1 if family is not AF_UNSPEC, and the parsed address family does not match family. On success, return 1, and store the result, if any, into result, if provided.
If accept_regular is set and the address is in neither recognized reverse lookup hostname format, try parsing the address as a regular IPv4 or IPv6 address too.
References hex_decode_digit(), INET_NTOA_BUF_LEN, strcasecmpend(), tor_addr_from_in6(), tor_addr_from_str(), and tor_inet_aton().
Referenced by connection_ap_handshake_send_resolve(), dns_resolve_impl(), and launch_resolve().
int tor_addr_port_parse | ( | const char * | s, | |
tor_addr_t * | addr_out, | |||
uint16_t * | port_out | |||
) |
Parse an address or address-port combination from s, resolve the address as needed, and put the result in addr_out and (optionally) port_out. Return 0 on success, negative on failure.
References eat_whitespace(), tor_addr_copy(), tor_addr_lookup(), tor_assert, tor_free, and tor_parse_long().
Referenced by parse_bridge_line(), and parse_port_config().
static INLINE struct in_addr * tor_addr_to_in | ( | const tor_addr_t * | a | ) | [static, read] |
Return an in_addr* equivalent to a, or NULL if a is not an IPv4 address.
References tor_addr_t::addr, tor_addr_t::family, and tor_addr_t::in_addr.
Referenced by launch_resolve().
static INLINE struct in6_addr * tor_addr_to_in6 | ( | const tor_addr_t * | a | ) | [static, read] |
Return an in6_addr* equivalent to a, or NULL if a is not an IPv6 address.
References tor_addr_t::addr, tor_addr_t::family, and tor_addr_t::in6_addr.
Referenced by connection_ap_get_original_destination(), connection_send_socks5_connect(), launch_resolve(), and tor_addr_to_sockaddr().
static INLINE uint32_t tor_addr_to_ipv4h | ( | const tor_addr_t * | a | ) | [static] |
Return an IPv4 address in host order for a, or 0 if a is not an IPv4 address.
References tor_addr_to_ipv4n().
Referenced by connection_or_set_state_open(), exit_policy_is_general_exit_helper(), get_interface_address(), is_local_addr(), routerset_contains(), tor_addr_compare_masked(), tor_addr_eq_ipv4h(), tor_addr_hash(), tor_addr_is_internal(), tor_addr_is_loopback(), tor_addr_to_reverse_lookup_name(), and tor_lookup_hostname().
static INLINE uint32_t tor_addr_to_ipv4n | ( | const tor_addr_t * | a | ) | [static] |
Return an IPv4 address in network order for a, or 0 if a is not an IPv4 address.
References tor_addr_t::addr, tor_addr_t::family, and tor_addr_t::in_addr.
Referenced by append_address_to_payload(), circuit_send_next_onion_skin(), connection_ap_get_original_destination(), connection_edge_end(), connection_edge_finished_connecting(), connection_exit_connect(), connection_proxy_connect(), connection_send_socks5_connect(), send_resolved_cell(), tor_addr_is_null(), tor_addr_to_ipv4h(), and tor_addr_to_sockaddr().
int tor_addr_to_reverse_lookup_name | ( | char * | out, | |
size_t | outlen, | |||
const tor_addr_t * | addr | |||
) |
Convert addr to an in-addr.arpa name or a .ip6.arpa name, and store the result in the outlen-byte buffer at out. Return 0 on success, -1 on failure.
References tor_addr_t::family, REVERSE_LOOKUP_NAME_BUF_LEN, tor_addr_to_ipv4h(), and tor_snprintf().
Referenced by connection_ap_handshake_send_resolve().
socklen_t tor_addr_to_sockaddr | ( | const tor_addr_t * | a, | |
uint16_t | port, | |||
struct sockaddr * | sa_out, | |||
socklen_t | len | |||
) |
Convert the tor_addr_t in a, with port in port, into a socklen object in *sa_out of object size len. If not enough room is free, or on error, return -1. Else return the length of the sockaddr.
References tor_addr_family(), tor_addr_to_in6(), and tor_addr_to_ipv4n().
Referenced by configure_nameservers(), and connection_connect().
const char* tor_addr_to_str | ( | char * | dest, | |
const tor_addr_t * | addr, | |||
int | len, | |||
int | decorate | |||
) |
Convert a tor_addr_t addr into a string, and store it in dest of size len. Returns a pointer to dest on success, or NULL on failure. If decorate, surround IPv6 addresses with brackets.
References tor_addr_t::addr, tor_addr_t::in6_addr, tor_addr_t::in_addr, tor_addr_family(), tor_assert, and tor_inet_ntop().
Referenced by connection_ap_get_original_destination(), fetch_from_buf_socks(), fmt_addr(), policy_write_item(), and tor_dup_addr().
char* tor_dup_addr | ( | const tor_addr_t * | addr | ) |
Return a newly allocated string with a representation of addr.
References tor_addr_to_str().
Referenced by connection_exit_begin_conn(), connection_handle_listener_read(), connection_or_init_conn_from_address(), evdns_server_callback(), launch_direct_bridge_descriptor_fetch(), and rend_encode_v2_intro_points().
char* tor_dup_ip | ( | uint32_t | addr | ) |
Given a host-order addr, call tor_inet_ntop() on it and return a strdup of the resulting address.
References tor_inet_ntop().
Referenced by directory_post_to_hs_dir(), dirserv_generate_networkstatus_vote_obj(), getinfo_helper_misc(), rep_hist_get_router_stability_doc(), router_rebuild_descriptor(), and trusted_dirs_load_certs_from_string().
int tor_inet_ntoa | ( | const struct in_addr * | in, | |
char * | buf, | |||
size_t | buf_len | |||
) |
Given an IPv4 in_addr struct *in (in network order, as usual), write it as a string into the buf_len-byte buffer in buf.
References tor_snprintf().
Referenced by addressmap_get_virtual_address(), client_dns_set_addressmap(), connection_edge_process_relay_cell_not_open(), directory_initiate_command_routerstatus_rend(), evdns_callback(), evdns_wildcard_check_callback(), fetch_from_buf_socks(), format_networkstatus_vote(), generate_v2_networkstatus_opinion(), log_addr_has_changed(), networkstatus_compute_consensus(), remap_event_helper(), resolve_my_address(), routerstatus_format_entry(), tell_controller_about_resolved_result(), and tor_inet_ntop().