mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
net: Add fmt_addrport_ap() and fmt_addr_family()
Add fmt_addrport_ap(), a macro that takes a tor_addr_port_t, and uses it to call fmt_addrport(). Add fmt_addr_family(), a function that returns a string constant describing the address family. Utility functions for 33817.
This commit is contained in:
@@ -1206,6 +1206,39 @@ fmt_addr32(uint32_t addr)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/** Return a string representing the family of <b>addr</b>.
|
||||
*
|
||||
* This string is a string constant, and must not be freed.
|
||||
* This function is thread-safe.
|
||||
*/
|
||||
const char *
|
||||
fmt_addr_family(const tor_addr_t *addr)
|
||||
{
|
||||
static int default_bug_once = 0;
|
||||
|
||||
IF_BUG_ONCE(!addr)
|
||||
return "NULL pointer";
|
||||
|
||||
switch (tor_addr_family(addr)) {
|
||||
case AF_INET6:
|
||||
return "IPv6";
|
||||
case AF_INET:
|
||||
return "IPv4";
|
||||
case AF_UNIX:
|
||||
return "UNIX socket";
|
||||
case AF_UNSPEC:
|
||||
return "unspecified";
|
||||
default:
|
||||
if (!default_bug_once) {
|
||||
log_warn(LD_BUG, "Called with unknown address family %d",
|
||||
(int)tor_addr_family(addr));
|
||||
default_bug_once = 1;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
//return "(unreachable code)";
|
||||
}
|
||||
|
||||
/** Convert the string in <b>src</b> to a tor_addr_t <b>addr</b>. The string
|
||||
* may be an IPv4 address, or an IPv6 address surrounded by square brackets.
|
||||
*
|
||||
|
||||
@@ -221,7 +221,9 @@ char *tor_addr_to_str_dup(const tor_addr_t *addr) ATTR_MALLOC;
|
||||
|
||||
const char *fmt_addr_impl(const tor_addr_t *addr, int decorate);
|
||||
const char *fmt_addrport(const tor_addr_t *addr, uint16_t port);
|
||||
#define fmt_addrport_ap(ap) fmt_addrport(&(ap)->addr, (ap)->port)
|
||||
const char *fmt_addr32(uint32_t addr);
|
||||
const char *fmt_addr_family(const tor_addr_t *addr);
|
||||
|
||||
MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family,
|
||||
tor_addr_t *addr));
|
||||
|
||||
Reference in New Issue
Block a user