aboutsummaryrefslogtreecommitdiff
path: root/p2p/src/utils/mod.rs
blob: e8ff9d0475f2a8495f5636b1e00cb2fd58914008 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mod version;

pub use version::{version_match, Version, VersionInt};

use std::net::IpAddr;

use karyons_net::Addr;

/// Check if two addresses belong to the same subnet.
pub fn subnet_match(addr: &Addr, other_addr: &Addr) -> bool {
    match (addr, other_addr) {
        (Addr::Ip(IpAddr::V4(ip)), Addr::Ip(IpAddr::V4(other_ip))) => {
            // XXX Consider moving this to a different location
            if other_ip.is_loopback() && ip.is_loopback() {
                return false;
            }
            ip.octets()[0..3] == other_ip.octets()[0..3]
        }
        _ => false,
    }
}