Get address for websockets clients.
This commit is contained in:
parent
91fa1c9625
commit
f61a8cbf74
@ -103,6 +103,15 @@ static struct libwebsocket_protocols protocols[] = {
|
|||||||
{ NULL, NULL, 0, 0, 0, NULL, 0}
|
{ 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,
|
static int callback_mqtt(struct libwebsocket_context *context,
|
||||||
struct libwebsocket *wsi,
|
struct libwebsocket *wsi,
|
||||||
enum libwebsocket_callback_reasons reason,
|
enum libwebsocket_callback_reasons reason,
|
||||||
@ -153,6 +162,13 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|||||||
}else{
|
}else{
|
||||||
return -1;
|
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;
|
break;
|
||||||
|
|
||||||
case LWS_CALLBACK_CLOSED:
|
case LWS_CALLBACK_CLOSED:
|
||||||
|
Loading…
Reference in New Issue
Block a user