Skip to content

Commit

Permalink
Skip link_local v4 addresses and v6 address when v6 is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge authored and garious committed Jun 14, 2018
1 parent ec713c1 commit 8b9713a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 1 addition & 13 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
}
}
Expand Down

0 comments on commit 8b9713a

Please sign in to comment.