diff --git a/Cargo.toml b/Cargo.toml index e1ad8509..e1dd4d5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadowsocks-rust" -version = "1.8.6" +version = "1.8.7" authors = ["Y. T. CHUNG "] description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls." repository = "https://github.com/zonyitoo/shadowsocks-rust" diff --git a/src/bin/server.rs b/src/bin/server.rs index 65b7eb1b..f554c187 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -7,6 +7,8 @@ //! *It should be notice that the extented configuration file is not suitable for the server //! side.* +use std::net::{IpAddr, SocketAddr}; + use clap::{App, Arg}; use futures::{ future::{self, Either}, @@ -153,9 +155,10 @@ fn main() { } if let Some(bind_addr) = matches.value_of("BIND_ADDR") { - let bind_addr = bind_addr - .parse::() - .expect("`bind-addr` invalid, (IP:Port) or (Domain:Port)"); + let bind_addr = match bind_addr.parse::() { + Ok(ip) => ServerAddr::from(SocketAddr::new(ip, 0)), + Err(..) => ServerAddr::from((bind_addr, 0)), + }; config.local = Some(bind_addr); } diff --git a/src/config.rs b/src/config.rs index 5f2d05e0..dd706497 100644 --- a/src/config.rs +++ b/src/config.rs @@ -199,9 +199,9 @@ impl From for ServerAddr { } } -impl From<(String, u16)> for ServerAddr { - fn from((dname, port): (String, u16)) -> ServerAddr { - ServerAddr::DomainName(dname, port) +impl> From<(I, u16)> for ServerAddr { + fn from((dname, port): (I, u16)) -> ServerAddr { + ServerAddr::DomainName(dname.into(), port) } } @@ -679,8 +679,18 @@ impl Config { // Standard config // Client if let Some(la) = config.local_address { - // Let system allocate port by default - let port = config.local_port.unwrap_or(0); + let port = match config.local_port { + // Let system allocate port by default + None => 0, + Some(p) => { + if config_type.is_server() { + // Server can only bind to address, port should always be 0 + 0 + } else { + p + } + } + }; let local = match la.parse::() { Ok(ip) => ServerAddr::from(SocketAddr::new(ip, port)),