aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/Resolver.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-02-10 20:30:10 +0100
committerMax Kellermann <max@duempel.org>2015-02-10 22:06:06 +0100
commit4e30e747390ac6bb6a6e5ededfbcdae937579393 (patch)
treebeb2d9acd687a62d476e796114efd8ea6b2f69ad /src/net/Resolver.cxx
parent42890b9acf50c4406b61b3b37078c00ec79411fa (diff)
downloadmpd-4e30e747390ac6bb6a6e5ededfbcdae937579393.tar.gz
mpd-4e30e747390ac6bb6a6e5ededfbcdae937579393.tar.xz
mpd-4e30e747390ac6bb6a6e5ededfbcdae937579393.zip
net/SocketAddress: light wrapper for struct sockaddr
Diffstat (limited to 'src/net/Resolver.cxx')
-rw-r--r--src/net/Resolver.cxx21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/net/Resolver.cxx b/src/net/Resolver.cxx
index 389b3d4b5..cfbce5ff6 100644
--- a/src/net/Resolver.cxx
+++ b/src/net/Resolver.cxx
@@ -19,6 +19,7 @@
#include "config.h"
#include "Resolver.hxx"
+#include "SocketAddress.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -43,13 +44,14 @@
const Domain resolver_domain("resolver");
std::string
-sockaddr_to_string(const struct sockaddr *sa, size_t length)
+sockaddr_to_string(SocketAddress address)
{
#ifdef HAVE_UN
- if (sa->sa_family == AF_UNIX) {
+ if (address.GetFamily() == AF_UNIX) {
/* return path of UNIX domain sockets */
- const sockaddr_un &s_un = *(const sockaddr_un *)sa;
- if (length < sizeof(s_un) || s_un.sun_path[0] == 0)
+ 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;
@@ -57,14 +59,15 @@ sockaddr_to_string(const struct sockaddr *sa, size_t length)
#endif
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
- const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)sa;
+ const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)
+ address.GetAddress();
struct sockaddr_in a4;
#endif
int ret;
char host[NI_MAXHOST], serv[NI_MAXSERV];
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
- if (sa->sa_family == AF_INET6 &&
+ if (address.GetFamily() == AF_INET6 &&
IN6_IS_ADDR_V4MAPPED(&a6->sin6_addr)) {
/* convert "::ffff:127.0.0.1" to "127.0.0.1" */
@@ -74,12 +77,12 @@ sockaddr_to_string(const struct sockaddr *sa, size_t length)
sizeof(a4.sin_addr));
a4.sin_port = a6->sin6_port;
- sa = (const struct sockaddr *)&a4;
- length = sizeof(a4);
+ address = { (const struct sockaddr *)&a4, sizeof(a4) };
}
#endif
- ret = getnameinfo(sa, length, host, sizeof(host), serv, sizeof(serv),
+ ret = getnameinfo(address.GetAddress(), address.GetSize(),
+ host, sizeof(host), serv, sizeof(serv),
NI_NUMERICHOST|NI_NUMERICSERV);
if (ret != 0)
return "unknown";