Skip link_local v4 addresses and v6 address when v6 is not enabled

This commit is contained in:
Stephen Akridge 2018-06-14 11:37:45 -07:00 committed by Greg Fitzgerald
parent ec713c18c4
commit 8b9713a934
2 changed files with 15 additions and 14 deletions

View File

@ -8,9 +8,8 @@ extern crate solana;
use atty::{is, Stream};
use getopts::Options;
use pnet::datalink;
use rayon::prelude::*;
use solana::crdt::{Crdt, ReplicatedData};
use solana::crdt::{get_ip_addr, Crdt, ReplicatedData};
use solana::mint::MintDemo;
use solana::ncp::Ncp;
use solana::signature::{GenKeys, KeyPair, KeyPairUtil};
@ -38,17 +37,6 @@ fn print_usage(program: &str, opts: Options) {
print!("{}", opts.usage(&brief));
}
fn get_ip_addr() -> Option<IpAddr> {
for iface in datalink::interfaces() {
for p in iface.ips {
if !p.ip().is_loopback() && !p.ip().is_multicast() {
return Some(p.ip());
}
}
}
None
}
fn main() {
env_logger::init().unwrap();
let mut threads = 4usize;

View File

@ -54,7 +54,20 @@ pub fn get_ip_addr() -> Option<IpAddr> {
for iface in datalink::interfaces() {
for p in iface.ips {
if !p.ip().is_loopback() && !p.ip().is_multicast() {
return Some(p.ip());
match p.ip() {
IpAddr::V4(addr) => {
if !addr.is_link_local() {
return Some(p.ip());
}
}
IpAddr::V6(_addr) => {
// Select an ipv6 address if the config is selected
#[cfg(feature = "ipv6")]
{
return Some(p.ip());
}
}
}
}
}
}