aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-02-28 15:20:35 +0100
committerMax Kellermann <max@duempel.org>2009-02-28 15:20:35 +0100
commit5c10d2ded7e14a5c155115e27ced5178546f0d05 (patch)
treef0ddae57e95fa0f306e38abb5daaddb7e5ff6339
parente085deb9444bc049401a4296c3e7ad87659a663a (diff)
downloadmpd-5c10d2ded7e14a5c155115e27ced5178546f0d05.tar.gz
mpd-5c10d2ded7e14a5c155115e27ced5178546f0d05.tar.xz
mpd-5c10d2ded7e14a5c155115e27ced5178546f0d05.zip
client: use sockaddr_to_string()
Removed the sockaddr_to_tmp_string() hack, use the new function sockaddr_to_string() instead.
Diffstat (limited to '')
-rw-r--r--src/client.c52
-rw-r--r--src/client.h2
-rw-r--r--src/listen.c2
3 files changed, 9 insertions, 47 deletions
diff --git a/src/client.c b/src/client.c
index f8abb846b..1cfa42aed 100644
--- a/src/client.c
+++ b/src/client.c
@@ -20,6 +20,7 @@
#include "command.h"
#include "conf.h"
#include "listen.h"
+#include "socket_util.h"
#include "permission.h"
#include "event_pipe.h"
#include "idle.h"
@@ -250,51 +251,10 @@ static void client_close(struct client *client)
g_free(client);
}
-static const char *
-sockaddr_to_tmp_string(const struct sockaddr *addr)
-{
- const char *hostname;
-
- switch (addr->sa_family) {
-#ifdef HAVE_TCP
- case AF_INET:
- hostname = (const char *)inet_ntoa(((const struct sockaddr_in *)
- addr)->sin_addr);
- if (!hostname)
- hostname = "error getting ipv4 address";
- break;
-#ifdef HAVE_IPV6
- case AF_INET6:
- {
- static char host[INET6_ADDRSTRLEN + 1];
- memset(host, 0, INET6_ADDRSTRLEN + 1);
- if (inet_ntop(AF_INET6, (const void *)
- &(((const struct sockaddr_in6 *)addr)->
- sin6_addr), host,
- INET6_ADDRSTRLEN)) {
- hostname = (const char *)host;
- } else {
- hostname = "error getting ipv6 address";
- }
- }
- break;
-#endif
-#endif /* HAVE_TCP */
-#ifdef HAVE_UN
- case AF_UNIX:
- hostname = "local connection";
- break;
-#endif /* HAVE_UN */
- default:
- hostname = "unknown";
- }
-
- return hostname;
-}
-
-void client_new(int fd, const struct sockaddr *addr, int uid)
+void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{
struct client *client;
+ char *remote;
if (num_clients >= client_max_connections) {
g_warning("Max Connections Reached!");
@@ -308,9 +268,11 @@ void client_new(int fd, const struct sockaddr *addr, int uid)
client_init(client, fd);
client->uid = uid;
+
+ remote = sockaddr_to_string(sa, sa_length, NULL);
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
- "[%u] opened from %s", client->num,
- sockaddr_to_tmp_string(addr));
+ "[%u] opened from %s", client->num, remote);
+ g_free(remote);
}
static int client_process_line(struct client *client, char *line)
diff --git a/src/client.h b/src/client.h
index d2e3301dc..f137f4e45 100644
--- a/src/client.h
+++ b/src/client.h
@@ -30,7 +30,7 @@ struct sockaddr;
void client_manager_init(void);
void client_manager_deinit(void);
-void client_new(int fd, const struct sockaddr *addr, int uid);
+void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid);
bool client_is_expired(const struct client *client);
diff --git a/src/listen.c b/src/listen.c
index b5a7b369a..c7f66e887 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -455,7 +455,7 @@ listen_in_event(G_GNUC_UNUSED GIOChannel *source,
if (fd >= 0) {
set_nonblocking(fd);
- client_new(fd, &sockAddr, get_remote_uid(fd));
+ client_new(fd, &sockAddr, socklen, get_remote_uid(fd));
} else if (fd < 0 && errno != EINTR) {
g_warning("Problems accept()'ing");
}