Fixed bug, server bind-addr should not contains a specific port

fix #189
This commit is contained in:
zonyitoo
2020-01-13 09:28:14 +08:00
parent 3c1d2c481d
commit 8117e50e36
3 changed files with 22 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "shadowsocks-rust"
version = "1.8.6"
version = "1.8.7"
authors = ["Y. T. CHUNG <zonyitoo@gmail.com>"]
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
repository = "https://github.com/zonyitoo/shadowsocks-rust"
+6 -3
View File
@@ -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::<ServerAddr>()
.expect("`bind-addr` invalid, (IP:Port) or (Domain:Port)");
let bind_addr = match bind_addr.parse::<IpAddr>() {
Ok(ip) => ServerAddr::from(SocketAddr::new(ip, 0)),
Err(..) => ServerAddr::from((bind_addr, 0)),
};
config.local = Some(bind_addr);
}
+15 -5
View File
@@ -199,9 +199,9 @@ impl From<SocketAddr> for ServerAddr {
}
}
impl From<(String, u16)> for ServerAddr {
fn from((dname, port): (String, u16)) -> ServerAddr {
ServerAddr::DomainName(dname, port)
impl<I: Into<String>> 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::<IpAddr>() {
Ok(ip) => ServerAddr::from(SocketAddr::new(ip, port)),