[Libwebsockets] Patch for Windows to allow bind to specific interface.

Andy Green andy at warmcat.com
Thu Nov 6 01:20:05 CET 2014



On 6 November 2014 02:49:52 GMT+08:00, Emerson Clarke <emerson at openfin.co> wrote:
>For further information on this issue, please see the following CWE
>vulnerability notice:
>
>http://cwe.mitre.org/data/definitions/605.html
>
>
>
>On Wed, Nov 5, 2014 at 6:05 PM, Emerson Clarke <emerson at openfin.co>
>wrote:
>> Hi,
>>
>> Ive been working with libwebsockets recently, and it seems like a
>well
>> written and very useful library, so many thanks.
>>
>> I did encounter one issue when trying to bind a websockets server on
>Windows.
>>
>> The problem was that another application kept stealing the port i was
>> using. This seemed to be because the other application used
>> SO_REUSEADDR and in combination with libwebsockets binding to 0.0.0.0
>> (INADDR_ANY) this was allowing the other application to steal its
>> port.

Good old windows.

>> The solution was to allow libwebsockets to bind to a specific
>> interface (i.e. 127.0.0.1), but there appeared to be no
>implementation

I see... specifically there is no implementation for *windows platform* (Linux works fine, the test server allows you to choose which network interface to bind to)

>> for:
>>
>> LWS_VISIBLE int
>> interface_to_sa(struct libwebsocket_context *context,
>> const char *ifname, struct sockaddr_in *addr, size_t addrlen)
>>
>> So i wrote one quickly that attempts to resolve a numeric ip and then
>> looks up the hostname otherwise.  If youd like to include it, that
>> would be great. An MIT or equivalent licence is hereby granted...
>>
>> The code should work on OSX/Linux etc also.

Linux / OSX / Android etc already has a better one which handles IPV6

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/tree/lib/lws-plat-unix.c#n317

>> LWS_VISIBLE int
>> interface_to_sa(struct libwebsocket_context *context,
>> const char *ifname, struct sockaddr_in *addr, size_t addrlen)
>> {
>>
>> long long address = inet_addr(ifname);
>> if (address == INADDR_NONE)
>> {
>>
>> struct hostent *entry = gethostbyname(ifname);
>> if (entry)
>> address = ((struct in_addr *)entry->h_addr_list[0])->s_addr;
>> }
>>
>> if (address == INADDR_NONE)
>> return -1;
>>
>> addr->sin_addr.s_addr = address;
>>
>> return 0;
>> }

Thanks.

However can I ask you to provide this as a patch on current git lib/lws-plat-win.c with a comment on top of your function that this particular function has the more liberal license, to your satisfaction?  Normally I don't care too much how contributions are coming but for windows, it's better that exactly what you saw build and work gets committed, and I don't want to generate any problems with the non-default license.

-Andy

>>
>> Regards,
>>
>> Emerson
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list