summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-04 08:43:55 +0100
committerMax Kellermann <max@duempel.org>2013-12-04 08:43:55 +0100
commite1901e97c2f3f6901ca7bac31a68ac9da1e3a4ee (patch)
treefac9794063e63a6e3e870a6455f13df54ef146fe /src/system
parentd694150372408cd80b89a2e27a88f91b5f856b67 (diff)
system/Resolver: sockaddr_to_string() returns std::string()
No GLib memory allocation.
Diffstat (limited to 'src/system')
-rw-r--r--src/system/Resolver.cxx28
-rw-r--r--src/system/Resolver.hxx13
2 files changed, 23 insertions, 18 deletions
diff --git a/src/system/Resolver.cxx b/src/system/Resolver.cxx
index 8f4f4dcda..6e0870403 100644
--- a/src/system/Resolver.cxx
+++ b/src/system/Resolver.cxx
@@ -44,17 +44,17 @@
const Domain resolver_domain("resolver");
-char *
-sockaddr_to_string(const struct sockaddr *sa, size_t length, Error &error)
+std::string
+sockaddr_to_string(const struct sockaddr *sa, size_t length)
{
#ifdef HAVE_UN
if (sa->sa_family == 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)
- return g_strdup("local");
+ return "local";
- return g_strdup(s_un.sun_path);
+ return s_un.sun_path;
}
#endif
@@ -83,17 +83,23 @@ sockaddr_to_string(const struct sockaddr *sa, size_t length, Error &error)
ret = getnameinfo(sa, length, host, sizeof(host), serv, sizeof(serv),
NI_NUMERICHOST|NI_NUMERICSERV);
- if (ret != 0) {
- error.Set(resolver_domain, ret, gai_strerror(ret));
- return NULL;
- }
+ if (ret != 0)
+ return "unknown";
#ifdef HAVE_IPV6
- if (strchr(host, ':') != NULL)
- return g_strconcat("[", host, "]:", serv, NULL);
+ if (strchr(host, ':') != NULL) {
+ std::string result("[");
+ result.append(host);
+ result.append("]:");
+ result.append(serv);
+ return result;
+ }
#endif
- return g_strconcat(host, ":", serv, NULL);
+ std::string result(host);
+ result.push_back(':');
+ result.append(serv);
+ return result;
}
struct addrinfo *
diff --git a/src/system/Resolver.hxx b/src/system/Resolver.hxx
index ec557d1a0..044d3f96a 100644
--- a/src/system/Resolver.hxx
+++ b/src/system/Resolver.hxx
@@ -22,6 +22,8 @@
#include "Compiler.h"
+#include <string>
+
#include <stddef.h>
struct sockaddr;
@@ -33,17 +35,14 @@ extern const Domain resolver_domain;
/**
* Converts the specified socket address into a string in the form
- * "IP:PORT". The return value must be freed with g_free() when you
- * don't need it anymore.
+ * "IP:PORT".
*
* @param sa the sockaddr struct
* @param length the length of #sa in bytes
- * @param error location to store the error occurring, or NULL to
- * ignore errors
*/
-gcc_malloc
-char *
-sockaddr_to_string(const sockaddr *sa, size_t length, Error &error);
+gcc_pure
+std::string
+sockaddr_to_string(const sockaddr *sa, size_t length);
/**
* Resolve a specification in the form "host", "host:port",