mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-14 08:14:45 +00:00
fix(shadowsocks): IP_UNICAST_IF requires index to be network endianess
ref #1266
This commit is contained in:
@@ -30,12 +30,7 @@ stream-cipher = ["shadowsocks-crypto/v1-stream"]
|
||||
aead-cipher-extra = ["shadowsocks-crypto/v1-aead-extra"]
|
||||
|
||||
# Enable AEAD 2022
|
||||
aead-cipher-2022 = [
|
||||
"shadowsocks-crypto/v2",
|
||||
"rand/small_rng",
|
||||
"aes",
|
||||
"lru_time_cache",
|
||||
]
|
||||
aead-cipher-2022 = ["shadowsocks-crypto/v2", "rand/small_rng", "aes"]
|
||||
# Enable AEAD 2022 with extra ciphers
|
||||
aead-cipher-2022-extra = ["aead-cipher-2022", "shadowsocks-crypto/v2-extra"]
|
||||
|
||||
@@ -57,7 +52,7 @@ pin-project = "1.1"
|
||||
bloomfilter = { version = "1.0.8", optional = true }
|
||||
thiserror = "1.0"
|
||||
rand = { version = "0.8", optional = true }
|
||||
lru_time_cache = { version = "0.11", optional = true }
|
||||
lru_time_cache = "0.11"
|
||||
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_urlencoded = "0.7"
|
||||
|
||||
@@ -40,6 +40,7 @@ use windows_sys::{
|
||||
IP_ADAPTER_ADDRESSES_LH,
|
||||
},
|
||||
Networking::WinSock::{
|
||||
htonl,
|
||||
setsockopt,
|
||||
WSAGetLastError,
|
||||
WSAIoctl,
|
||||
@@ -334,20 +335,27 @@ async fn set_ip_unicast_if<S: AsRawSocket>(socket: &S, addr: &SocketAddr, iface:
|
||||
unsafe {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
|
||||
let ret = match addr {
|
||||
SocketAddr::V4(..) => setsockopt(
|
||||
handle,
|
||||
IPPROTO_IP as i32,
|
||||
IP_UNICAST_IF as i32,
|
||||
&if_index as *const _ as PCSTR,
|
||||
mem::size_of_val(&if_index) as i32,
|
||||
),
|
||||
SocketAddr::V6(..) => setsockopt(
|
||||
handle,
|
||||
IPPROTO_IPV6 as i32,
|
||||
IPV6_UNICAST_IF as i32,
|
||||
&if_index as *const _ as PCSTR,
|
||||
mem::size_of_val(&if_index) as i32,
|
||||
),
|
||||
SocketAddr::V4(..) => {
|
||||
// Interface index is in network byte order for IPPROTO_IP.
|
||||
let if_index = htonl(if_index);
|
||||
setsockopt(
|
||||
handle,
|
||||
IPPROTO_IP as i32,
|
||||
IP_UNICAST_IF as i32,
|
||||
&if_index as *const _ as PCSTR,
|
||||
mem::size_of_val(&if_index) as i32,
|
||||
)
|
||||
}
|
||||
SocketAddr::V6(..) => {
|
||||
// Interface index is in host byte order for IPPROTO_IPV6.
|
||||
setsockopt(
|
||||
handle,
|
||||
IPPROTO_IPV6 as i32,
|
||||
IPV6_UNICAST_IF as i32,
|
||||
&if_index as *const _ as PCSTR,
|
||||
mem::size_of_val(&if_index) as i32,
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
if ret == SOCKET_ERROR {
|
||||
|
||||
Reference in New Issue
Block a user