[Libwebsockets] how to get port number of client side

Brice Hamon brice at ydotm.com
Fri Oct 2 11:29:54 CEST 2015


That's what I do.

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

libwebsockets_get_peer_addresses(wsicont,
                                wsi, fd,
                                client_name, sizeof(client_name),
                                remote_client_ip, sizeof(remote_client_ip));

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

On Fri, Oct 2, 2015 at 5:19 AM, Roger Light <andy.green at linaro.org> wrote:

> Hi Susy,
>
> You should get the socket from lws using libwebsocket_get_socket_fd(),
> then use getpeername() to get information about the remote side of the
> connection.
>
> http://www.retran.com/beej/getpeernameman.html
>
> Cheers,
>
> Roger
>
>
> On Thu, Oct 1, 2015 at 8:11 AM, amber susy <andy.green at linaro.org> wrote:
> > Hi all,
> >
> > How can I solve, that when a client connects to the websocket server, the
> > server gets the information what the port number the client uses is?
> (port
> > on client side)
> >
> > I would need this to differentiate clients from same LAN (connecting from
> > behind the same router).
> > For such clients, the IP -currently without port- is same, thus not
> enough
> > to differentiate them.
> >
> > Thanks and Regards
> > Susy
> >
> > _______________________________________________
> > Libwebsockets mailing list
> > Libwebsockets at ml.libwebsockets.org
> > http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
> >
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20151002/0f05d442/attachment-0001.html>


More information about the Libwebsockets mailing list