Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ipv6 #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

LinusCDE
Copy link

The current implementation assumes all resolved addresses to be ipv4 by binding the udp socket to 0.0.0.0.

Rust the ToSocketAddrs trait returns an iterator over resolved socket addresses (ip, port). This iterator can contain IPv4 as well as IPv6 addresses (depending on the system).

For example, 2.pool.ntp.org resolves to a bunch of IPv4 and IPv6 addresses. Since the call to UdpSocket::send_to(...) just sends the packet to the first socket address of this iterator, it attempts to send it to an IPv6 Address in this case, which fails since the UdpSocket was bound to an IPv4 address, this creates an address family conflict:

# Run example "request" but change address to "2.pool.ntp.org:123" on a host with native IPv6 internet:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 97, kind: Uncategorized, message: "Address family not supported by protocol" }', examples/request.rs:15:65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This PR just does the "take the first address" itself and checks whether that address is IPv4 or IPv6 to change the bind address accordingly. This gets the above working while also adding support for IPv6 in general (e.g. using the address [2a01:4f8:201:7454::35]:123).

(A nice side effect is, that this separates the dns resolution from the actual transmission, making it more reliable to add an offset based on the packet roundtrip.)


Workaround

For now the workaround is to use a similar approach before request(...) and select the first ipv4 address by filtering. It also does the dns resolution at that point, enabling the manual calculation of a roundtrip for a rough offset adjustment (which I'm currently doing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant