From f61a8cbf74606eb06e07836672324e8dd5fc0a15 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 17 Sep 2014 22:19:45 +0100 Subject: [PATCH] Get address for websockets clients. --- src/websockets.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/websockets.c b/src/websockets.c index 958b90f5..0d52011f 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -103,6 +103,15 @@ static struct libwebsocket_protocols protocols[] = { { NULL, NULL, 0, 0, 0, NULL, 0} }; +static void easy_address(int sock, struct mosquitto *mosq) +{ + char address[1024]; + + if(!_mosquitto_socket_get_address(sock, address, 1024)){ + mosq->address = _mosquitto_strdup(address); + } +} + static int callback_mqtt(struct libwebsocket_context *context, struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, @@ -153,6 +162,13 @@ static int callback_mqtt(struct libwebsocket_context *context, }else{ return -1; } + easy_address(libwebsocket_get_socket_fd(wsi), mosq); + if(!mosq->address){ + /* getpeername and inet_ntop failed and not a bridge */ + _mosquitto_free(mosq); + u->mosq = NULL; + return -1; + } break; case LWS_CALLBACK_CLOSED: