summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-05-03 14:45:40 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-05-03 14:45:40 +0200
commitda3e1bec8f45feddaee41ba02562207f4b7ad1f7 (patch)
tree313c5c21577e24d9e0fb0b245bbe7195c8dbb923 /server
parentad59e49be04de7e2e6adda62eb39613c40c3a1be (diff)
Print peer address on connection.
Diffstat (limited to 'server')
-rw-r--r--server/src/httpd.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/src/httpd.cc b/server/src/httpd.cc
index 62e4c9f..10bd5bb 100644
--- a/server/src/httpd.cc
+++ b/server/src/httpd.cc
@@ -42,6 +42,11 @@
#include "debug.h"
+// for inet_ntop
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
typedef struct {
void *ptr;
bool firstrun;
@@ -71,6 +76,14 @@ static int request_handler(void *cls,
{
time_t now = time(NULL);
DEBUG(httpd, "Request time: %s", ctime(&now));
+
+ struct sockaddr *so;
+ so = MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
+
+ char peeraddr[INET_ADDRSTRLEN];
+ inet_ntop(AF_INET, &((struct sockaddr_in*)so)->sin_addr, peeraddr, sizeof(peeraddr));
+ DEBUG(httpd, "peer: %s\n", peeraddr);
+
DEBUG(httpd, "request_handler: cls(%p) con(%p) url(%s) method(%s)"
" version(%s) *con_cls(%p)\n",
cls, con, url, method, version, *con_cls);