Skip to content

Commit

Permalink
fix(shadowsocks): check mptcp socket() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Sep 9, 2024
1 parent c31719a commit fa21a30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/shadowsocks/src/net/sys/unix/bsd/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl TcpStream {

let socket = unsafe {
let fd = libc::socket(AF_MULTIPATH, libc::SOCK_STREAM, libc::IPPROTO_TCP);
if fd < 0 {
let err = io::Error::last_os_error();
return Err(err);
}
let socket = Socket::from_raw_fd(fd);
socket.set_nonblocking(true)?;
TcpSocket::from_raw_fd(socket.into_raw_fd())
Expand Down
6 changes: 6 additions & 0 deletions crates/shadowsocks/src/net/sys/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,18 @@ pub fn set_tcp_fastopen<S: AsRawFd>(socket: &S) -> io::Result<()> {
}

fn create_mptcp_socket(bind_addr: &SocketAddr) -> io::Result<TcpSocket> {
// https://www.kernel.org/doc/html/next/networking/mptcp.html

unsafe {
let family = match bind_addr {
SocketAddr::V4(..) => libc::AF_INET,
SocketAddr::V6(..) => libc::AF_INET6,
};
let fd = libc::socket(family, libc::SOCK_STREAM, libc::IPPROTO_MPTCP);
if fd < 0 {
let err = io::Error::last_os_error();
return Err(err);
}
let socket = Socket::from_raw_fd(fd);
socket.set_nonblocking(true)?;
Ok(TcpSocket::from_raw_fd(socket.into_raw_fd()))
Expand Down

0 comments on commit fa21a30

Please sign in to comment.