[Libwebsockets] How to obtain the IP address of the client

Brice Hamon brice at ydotm.com
Fri Nov 8 17:42:19 CET 2019


That's how I do it, in my protocol callback function.

 case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
        {
            char client_name[512];
            char remote_client_ip[64];
            int fd = 0;
            if (wsi)
                fd = lws_get_socket_fd(wsi);

            lws_get_peer_addresses(wsi, fd,
                                client_name, sizeof(client_name),
                                remote_client_ip, sizeof(remote_client_ip));

            websocket->log(LOG_INFO, "WS protocol: websocket request from
%s (%s)",
                                client_name, remote_client_ip);
            break;
        }



On Fri, Nov 8, 2019 at 11:26 AM Stefano Mora <stefano.mora at newdep.com>
wrote:

> Hi all,
> is there a way to get the IP address of the connected client(s) ?
> In which phase I can obtain it/them?
>
> I saw the lws_get_peer_addresses function but I don't have the fd
> parameter..
> Thanks
>
>
> Stefano Mora / SW Engineer
> stefano.mora at newdep.com
>
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20191108/c399dc1d/attachment.htm>


More information about the Libwebsockets mailing list