Skip to content

Creating listening socket seems to now be having IPv4/IPv6 issues #7

@fearworksmedia

Description

@fearworksmedia

When creating a listening socket, to create a webserver for example, I just discovered on my Windows 10 and Windows 11 installs that the webserver would only respond on localhost. Trying 127.0.0.1 would not work, nor would the IPv4 address assigned to the PC. It looks like Windows has had some sort of update that, by default, is using IPv6 over IPv4, and the listening socket is defaulting to the IPv6 socket it finds first.

Sure enough when I change:

DWORD dwResult = getaddrinfo(NULL, pService, &hints, &result);

to:

DWORD dwResult = getaddrinfo("1.2.3.4", pService, &hints, &result);

to force the DLL to only look for that particular address, the listening socket is then created on that specific IP address.

I am guessing that at some point very recently Windows has changed from retrieving IPv4 information first by default, to retrieiving IPv6 information first by default, when using getaddrinfo.

To go along with this, I would propose adding functionality that retrieves a list of the IPv4 and IPv6 addressses on the system to allow the user to then choose and specify the one they want when creating the listening socket.

I will attempt to add a pull request with modified code but it may get ugly because I don't really know what I am doing... feel free to stop me, and correct me if anything I have said is inaccurate. It is my interpretation based on a few MSDN and Stackflow pages I have researched, and I may be misunderstanding, misinterpreting or just downright imagining stuff that isn't true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions