Skip to content

IPv6 socket host and peer queries return an IPv4 address instead of the endpoint #218

Open

Description

@dimensionscape

IPv6 TCP connections work, but querying their local and remote endpoints returns an IPv4-looking 0.0.0.0 instead of the actual IPv6 address.

Regression coverage first: test/regression/SocketIpv6Endpoint, using the existing regression layout. Bind a listener to ::1 with an ephemeral port, connect a client to that port, accept it, and check listener.host(), client.host(), client.peer() and accepted.peer(). All four addresses should be ::1. Add an explicit IPv6 availability check for platforms without IPv6 loopback in CI.

Confirmed on Linux x86_64 with Haxe 4.3.3:

listener address: 0.0.0.0
client local address: 0.0.0.0
client peer address: 0.0.0.0
server peer address: 0.0.0.0

The connection itself succeeds. In src/hx/libs/std/Socket.cpp, socket_host, socket_peer and socket_accept use sockaddr_in even for AF_INET6 sockets. host/peer interpret the returned IPv6 structure as an IPv4 structure. The location interpreted as the IPv4 address is the IPv6 flow-info field, not the IPv6 address. accept discards the truncated address, so it still creates a usable accepted socket.

Use sockaddr_storage or family-appropriate structures and preserve the address family, full address and relevant IPv6 scope information. The legacy host/peer ABI returns only two Int values, so fixing the public Host result needs an additive native interface and a coordinated Haxe cpp standard-library change. Its current wrapper always constructs an IPv4 Host from that integer result.

Check that ports still round-trip correctly, cover IPv4 as a control, and add scoped-address coverage where available. Do not silently reinterpret an unsupported address family as IPv4.

No runtime implementation changes are included.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions