RPECDMZ4O7MMU32H6Z7EW75GRVEQ6IJYNPWSV54HUPTCX5H7I26QC
VODZCAIINDFQAU6RUV5VBRGJSMCWNMYAQ3ZE56SNBYU2WOSHFOMAC
KWR2TS2D7YN4LCGMQZ35V4WBLQDHAVSZJV3SZAIR5HQRSJAWLWCQC
LSQ7OPL7Z5WJDO7ZZS3D4UPMEEWUUF2LNQ3FZUWWFUVZEXA7CIOAC
7RMAZDLQ6FEEQGUUAIVEM4X2VME7IUUZMEJMMV3H46U3UKO4BODQC
LKAUS67VU5SLG5O5MTSO6N4VVT5OB2X4VNR6HYLIJ3ZOAXRQ4Q2QC
K3I54HXNNCTEA7L6UGWIVBFB5TPZVZZXDBRSR2YZDIKREXQVWRIQC
WX2TUKTGV5XK5F5GMEUDU2IHT3LRW2IQRE2BRAH76CTJIVUFMQCAC
LBG7DYYI7WCROF4GRYVXDXIV2465E5KPGQVZTFUPTZQBNZZ3LNYAC
// Interpret other's None addresses as the src address
let other_addr = match other_screen.addr {
Some(addr) => addr.0,
None => src,
};
for screen in &mut self.screens {
// Interpret self's None addresses as a null address
// TODO: Use getifaddrs to lookup matching interface address
let screen_addr = match screen.addr {
Some(addr) => addr.0,
None => net::SocketAddr::V4(net::SocketAddrV4::new(net::Ipv4Addr::new(0, 0, 0, 0), 0)),
};
// If same address, replace screen with other_screen
if screen_addr == other_addr {
// TODO: Merge screen properties
// *screen = *other_screen;
continue 'outer;
for other_addr in &other_screen.addrs {
for screen in &self.screens {
for addr in &screen.addrs {
if addr.0.ip() == other_addr.0.ip() {
// TODO: Merge screens
continue 'outer;
}
}
}
pub fn reset_local(&mut self) {
'outer: for ip in util::my_ips().unwrap() {
for (i, screen) in self.screens.iter().enumerate() {
for addr in &screen.addrs {
if addr.0.ip() == ip {
println!("Local screen at {}", i);
self.local = i as Index;
return;
}
}
}
}
panic!("Local IP was not found in cluster");
addr: None, // None implies local machine
addrs: util::my_ips().unwrap().into_iter()
.filter_map(|addr| match addr {
net::IpAddr::V4(addr) =>
if !addr.is_loopback() {
Some(net::SocketAddr::V4(net::SocketAddrV4::new(addr, port)))
} else { None },
net::IpAddr::V6(addr) =>
if !addr.is_loopback() {
Some(net::SocketAddr::V6(net::SocketAddrV6::new(addr, port, 0, 0)))
} else { None },
})
.map(|addr| Addr(addr))
.collect::<Vec<_>>(),
// event => match self.cluster.filter_net_event(event) {
// Some(event) => { self.host.send_event(event); },
// None => (),
// },
_ => (),
event => match self.cluster.filter_net_event(event) {
Some(event) => { self.host.send_event(event); },
None => (),
},
use nix;
use nix::errno::Errno;
use nix::sys::socket::{Ipv4Addr, Ipv6Addr, sockaddr_in, sockaddr_in6};
use std::{net, ptr};
use libc::{getifaddrs, freeifaddrs, AF_INET, AF_INET6};
/*
* Obtain a list of ip addresses for each interface
*/
pub fn my_ips() -> Result<Vec<net::IpAddr>, nix::Error> {
let mut addrs = Vec::new();
unsafe {
let mut list = ptr::null_mut();
if getifaddrs(&mut list) != 0 {
return Err(nix::Error::Sys(Errno::last()));
}
let mut ptr = list;
while !ptr.is_null() {
if !(*ptr).ifa_addr.is_null() {
match (*(*ptr).ifa_addr).sa_family as i32 {
AF_INET => {
let sa = (*ptr).ifa_addr as *const sockaddr_in;
addrs.push(net::IpAddr::V4(Ipv4Addr((*sa).sin_addr).to_std()));
},
AF_INET6 => {
let sa = (*ptr).ifa_addr as *const sockaddr_in6;
addrs.push(net::IpAddr::V6(Ipv6Addr((*sa).sin6_addr).to_std()));
},
_ => (),
}
}
ptr = (*ptr).ifa_next;
}
freeifaddrs(list);
};
Ok(addrs)
}