示例#1
0
/*
 * Calculate a netmask of length 'l' for address family 'af' and
 * store it in 'n'.
 * Returns 0 on success, -1 on failure.
 */
static int
addr_hostmask(int af, u_int l, struct xaddr *n)
{
	if (addr_netmask(af, l, n) == -1 || addr_invert(n) == -1)
		return (-1);
	return (0);
}
示例#2
0
int addr_host_to_all0s(struct xaddr* a, int masklen) {
    struct xaddr tmp_mask;

    if (addr_netmask(a->af, masklen, &tmp_mask) == -1)
        return (-1);
    if (addr_and(a, a, &tmp_mask) == -1)
        return (-1);
    return (0);
}
示例#3
0
int addr_netmatch(const struct xaddr* host, const struct xaddr* net, int masklen) {
    struct xaddr tmp_mask, tmp_result;

    if (host->af != net->af)
        return(-1);

    if (addr_netmask(host->af, masklen, &tmp_mask) == -1)
        return (-1);
    if (addr_and(&tmp_result, host, &tmp_mask) == -1)
        return (-1);
    return (addr_cmp(&tmp_result, net));
}
示例#4
0
int addr_host_is_all1s(const struct xaddr* a, int masklen) {
    struct xaddr tmp_addr, tmp_mask, tmp_result;

    rte_memcpy(&tmp_addr, a, sizeof(tmp_addr));
    if (addr_netmask(a->af, masklen, &tmp_mask) == -1)
        return (-1);
    if (addr_or(&tmp_result, &tmp_addr, &tmp_mask) == -1)
        return (-1);
    if (addr_invert(&tmp_result) == -1)
        return (-1);
    return (addr_is_all0s(&tmp_result));
}