From 34b384c23d9ed57be605c75440488e0766e468bc Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Aug 2017 13:34:07 +0200 Subject: [PATCH] api: show remote address in log --- include/villas/api/session.h | 5 +++++ lib/api.c | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/villas/api/session.h b/include/villas/api/session.h index 6c239e501..ccf69b1f7 100644 --- a/include/villas/api/session.h +++ b/include/villas/api/session.h @@ -54,6 +54,11 @@ struct api_session { struct web_buffer body; /**< HTTP body / WS payload */ struct web_buffer headers; /**< HTTP headers */ } response; + + struct { + char name[64]; + char ip[64]; + } peer; bool completed; /**< Did we receive the complete body yet? */ diff --git a/lib/api.c b/lib/api.c index 9c990ca76..b11e1db01 100644 --- a/lib/api.c +++ b/lib/api.c @@ -55,8 +55,10 @@ int api_ws_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void * ret = api_session_init(s, w->api, API_MODE_WS); if (ret) return -1; + + lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), s->peer.name, sizeof(s->peer.name), s->peer.ip, sizeof(s->peer.ip)); - debug(LOG_API, "New API session initiated: version=%d, mode=websocket", s->version); + debug(LOG_API, "New API session initiated: version=%d, mode=websocket, remote=%s (%s)", s->version, s->peer.name, s->peer.ip); break; case LWS_CALLBACK_CLOSED: @@ -117,8 +119,10 @@ int api_http_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void ret = api_session_init(s, w->api, API_MODE_HTTP); if (ret) return -1; + + lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), s->peer.name, sizeof(s->peer.name), s->peer.ip, sizeof(s->peer.ip)); - debug(LOG_API, "New API session initiated: version=%d, mode=http", s->version); + debug(LOG_API, "New API session initiated: version=%d, mode=http, remote=%s (%s)", s->version, s->peer.name, s->peer.ip); /* Prepare HTTP response header */ const char headers[] = "HTTP/1.1 200 OK\r\n"