Exemplo n.º 1
0
static void ip_addr_check(void)
{
    ip_addr_cmp_check_(&a, &a, 0);
    ip_addr_cmp_check_(&a, &b, -1);
    ip_addr_cmp_check_(&b, &a, 1);

    assert(!ip_addr_is_v6(&a) && !ip_addr_is_v6(&b));
}
Exemplo n.º 2
0
char const *ip_addr_2_strv6(struct ip_addr const *addr)
{
    if (ip_addr_is_v6(addr)) return ip_addr_2_str(addr);

    char *str = tempstr();
    snprintf(str, TEMPSTR_SIZE, "::ffff:%"PRINIPQUAD, NIPQUAD(&addr->u.v4));
    return str;
}
Exemplo n.º 3
0
bool ip_addr_is_broadcast(struct ip_addr const *addr)
{
    if (ip_addr_is_v6(addr)) {
        static uint8_t all_nodes[16] = {
            0xff, 0x02, 0, 0, 0, 0, 0, 0,
            0,    0, 0, 0, 0, 0, 0, 1,
        };
        ASSERT_COMPILE(sizeof(all_nodes) == sizeof(addr->u.v6.s6_addr));
        return 0 == memcmp(addr->u.v6.s6_addr, all_nodes, sizeof(all_nodes));
    } else {
        uint32_t netmask = netmask_of_address(addr->u.v4);
        return (netmask | ntohl(addr->u.v4.s_addr)) == 0xffffffffU;
    }
}
Exemplo n.º 4
0
bool ip_addr_is_routable(struct ip_addr const *addr)
{
    if (ip_addr_is_v6(addr)) return true;
    uint32_t const a = ntohl(addr->u.v4.s_addr);
    /* Non routable IP addresses :
     * private addresses :
     * 10.0.0.0    to 10.255.255.255  ie 0x0a000000 to 0x0affffff
     * 172.16.0.0  to 172.31.255.255  ie 0xac100000 to 0xac1fffff
     * 192.168.0.0 to 192.168.255.255 ie 0xc0a80000 to 0xc0a8ffff
     * loopback :
     * 127.0.0.0   to 127.255.255.255 ie 0x7f000000 to 0x7fffffff
     * other non-routable :
     * 169.254.0.0 to 169.254.255.255 ie 0xa9fe0000 to 0xa9feffff
     */
    return
        (a < 0x0a000000U || a > 0x0affffffU) &&
        (a < 0xac100000U || a > 0xac1fffffU) &&
        (a < 0xc0a80000U || a > 0xc0a8ffffU) &&
        (a < 0x7f000000U || a > 0x7fffffffU) &&
        (a < 0xa9fe0000U || a > 0xa9feffffU);
}