ducaale / xh

Friendly and fast tool for sending HTTP requests
MIT License
4.96k stars 90 forks source link

Directly bind to interface name on supported platforms #359

Closed ducaale closed 2 months ago

ducaale commented 3 months ago

The latest release of reqwest (v0.12) has added ClientBuilder::interface() which removes the need for translating interface names to IP addresses before binding to them.

However, this is only supported on limited platforms i.e linux, android and fuchsia so we still can't remove the network-interface crate/feature.

Depends on #357

ducaale commented 2 months ago

xh --interface=lo example.org now hangs forever. (It used to give a connect error.) Any idea?

I'm not really sure. But if cURL is behaving the same, then it should be okay?

$ curl http://example.org/ --interface lo
curl: (28) Failed to connect to example.org port 80 after 131767 ms: Connection timed out
blyxxyz commented 2 months ago

Another difference is that my (disconnected) ethernet interfaces now also hang forever while the old implementation gave a "Couldn't bind" error (because NetworkInterface::show() returned it without an IP address).

The crux seems to be that reqwest uses SO_BINDTODEVICE to basically hand the interface name directly to the kernel instead of the IP address thing we were doing.

But yeah, it matches curl, good point. So it's probably for the best.