diff options
author | Max Kellermann <max@duempel.org> | 2015-02-10 22:46:04 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-02-10 22:46:04 +0100 |
commit | cf5c10bbe60be6dde40f2a5e9244b3e6ee77c298 (patch) | |
tree | e8bc47c8a45409e7a2646735b4df33be043da3df /src/net/Resolver.cxx | |
parent | 4e30e747390ac6bb6a6e5ededfbcdae937579393 (diff) |
net/Resolver: move code to LocalAddressToString()
Diffstat (limited to 'src/net/Resolver.cxx')
-rw-r--r-- | src/net/Resolver.cxx | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/net/Resolver.cxx b/src/net/Resolver.cxx index cfbce5ff6..c7a684263 100644 --- a/src/net/Resolver.cxx +++ b/src/net/Resolver.cxx @@ -43,19 +43,27 @@ const Domain resolver_domain("resolver"); +#ifdef HAVE_UN + +static std::string +LocalAddressToString(const struct sockaddr_un &s_un, size_t size) +{ + if (size < sizeof(s_un) || s_un.sun_path[0] == 0) + return "local"; + + return s_un.sun_path; +} + +#endif + std::string sockaddr_to_string(SocketAddress address) { #ifdef HAVE_UN - if (address.GetFamily() == AF_UNIX) { + if (address.GetFamily() == AF_UNIX) /* return path of UNIX domain sockets */ - const sockaddr_un &s_un = *(const sockaddr_un *) - address.GetAddress(); - if (address.GetSize() < sizeof(s_un) || s_un.sun_path[0] == 0) - return "local"; - - return s_un.sun_path; - } + return LocalAddressToString(*(const sockaddr_un *)address.GetAddress(), + address.GetSize()); #endif #if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED) |