Hey,
I would like to perform a HTTP query with Socket using a specific linux interface, by example eth1, how its possible to do this ?
Thank you!!
We don't have this option. I don't know if we want to add it, as there is (to my knowledge) no similar Windows option so it wouldn't be portable.
For now, you can get the socket from Socket.SafeHandle and P/Invoke setsockopt. https://github.com/dotnet/corefx/issues/37122 may provide an alternate option in the future.
I don鈥檛 have an immediate need for this, but imagine a machine with multiple NICs where they鈥檙e connected to different networks and you have to go out a specific interface to reach the correct endpoint, what is the recommended way to send the request in that scenario?
I think it's important to implement this feature or a way to make a TCP connection through an existent network adapter!
Seems like Windows too have setsockopt in Winsock.h: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt.
Seems like Windows too have setsockopt in Winsock.h: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt.
@am11, he wasn't saying that setsockopt isn't available, he was saying that Windows doesn't have an equivalent to SO_BINDTODEVICE.
what is the recommended way to send the request in that scenario?
Can you just Bind to the IP address associated with the desired NIC?
Alternatively you can do what @scalablecory suggested and P/Invoke to setsockopt to set the relevant option.
I don't know if we want to add it, as there is (to my knowledge) no similar Windows option so it wouldn't be portable.
While in an ideal world every option would be available everywhere, at this layer of the stack there are bound to be OS differences as to what's supported. We have options in SocketOptionName that are supported on Windows but not on Unix (or on Linux but not on macOS)... I think it's reasonable to add options that are supported on Linux but not on Windows.
Duplicate of dotnet/runtime#865
Most helpful comment
@am11, he wasn't saying that setsockopt isn't available, he was saying that Windows doesn't have an equivalent to SO_BINDTODEVICE.
Can you just Bind to the IP address associated with the desired NIC?
Alternatively you can do what @scalablecory suggested and P/Invoke to setsockopt to set the relevant option.
While in an ideal world every option would be available everywhere, at this layer of the stack there are bound to be OS differences as to what's supported. We have options in SocketOptionName that are supported on Windows but not on Unix (or on Linux but not on macOS)... I think it's reasonable to add options that are supported on Linux but not on Windows.