arriven / db1000n

MIT License
1.18k stars 208 forks source link

Implement --interface option for non-linux systems #529

Open arriven opened 2 years ago

arriven commented 2 years ago

--interface option uses syscall.BindToDevice which is only available for linux. It should be possible to use net.InterfaceByName inside conn.Control to get an addr that could then be transformed into sockaddr for regular syscall.Bind which is available for all unix systems. Doing it in the control function should be enough to not have troubles when network changes at runtime

arriven commented 2 years ago

I think I've implemented it in https://github.com/Arriven/db1000n/commit/9fbca3f1cc29d8a1e67655886f0ed57b6f9a1240 but it needs some additional testing

@deputinizer you were the one who initially requested the feature, can you check if this implementation has any issues compared to BindToDevice?

deputinizer commented 2 years ago

Looks like windows just binds to IPv4 https://github.com/hyperium/hyper/blob/e8d523e579a262e5901a00e6248bd315f0352afe/src/client/connect/http.rs#L592

https://stackoverflow.com/questions/12603096/how-to-make-a-tcp-socket-work-with-so-bindtodevice-against-routing-table

arriven commented 2 years ago

Yeah, I'm not looking to implementing that on windows, just wanted to ensure that it works properly on unix without BindToDevice