Move public IP address detection out of bash
This commit is contained in:
@@ -4,6 +4,7 @@ extern crate solana;
|
||||
|
||||
use getopts::Options;
|
||||
use solana::crdt::{get_ip_addr, parse_port_or_addr, ReplicatedData};
|
||||
use solana::nat::get_public_ip_addr;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
@@ -19,7 +20,16 @@ fn print_usage(program: &str, opts: Options) {
|
||||
fn main() {
|
||||
let mut opts = Options::new();
|
||||
opts.optopt("b", "", "bind", "bind to port or address");
|
||||
opts.optflag("d", "dyn", "detect network address dynamically");
|
||||
opts.optflag(
|
||||
"p",
|
||||
"",
|
||||
"detect public network address using public servers",
|
||||
);
|
||||
opts.optflag(
|
||||
"l",
|
||||
"",
|
||||
"detect network address from local machine configuration",
|
||||
);
|
||||
opts.optflag("h", "help", "print help");
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
@@ -37,10 +47,14 @@ fn main() {
|
||||
|
||||
let bind_addr: SocketAddr = {
|
||||
let mut bind_addr = parse_port_or_addr(matches.opt_str("b"));
|
||||
if matches.opt_present("d") {
|
||||
if matches.opt_present("l") {
|
||||
let ip = get_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
if matches.opt_present("p") {
|
||||
let ip = get_public_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
bind_addr
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user