Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

netmask

Network mask


Description

prefix_length(), netmask() and hostmask() extract different (but equivalent) representations of the network mask. They accept an ip_network or ip_interface vector.

The functions can also convert between these alternative representations. For example, prefix_length() can infer the prefix length from an ip_address vector of netmasks and/or hostmasks, while netmask() and hostmask() can accept a vector of prefix lengths.

Usage

prefix_length(...)

netmask(...)

hostmask(...)

## S3 method for class 'ip_network'
prefix_length(x, ...)

## S3 method for class 'ip_network'
netmask(x, ...)

## S3 method for class 'ip_network'
hostmask(x, ...)

## S3 method for class 'ip_interface'
prefix_length(x, ...)

## S3 method for class 'ip_interface'
netmask(x, ...)

## S3 method for class 'ip_interface'
hostmask(x, ...)

## Default S3 method:
prefix_length(mask, ...)

## Default S3 method:
netmask(prefix_length, is_ipv6, ...)

## Default S3 method:
hostmask(prefix_length, is_ipv6, ...)

Arguments

...

Arguments to be passed to other methods

x

An ip_network or ip_interface vector

mask

An ip_address vector of netmasks and/or hostmasks. Ambiguous cases (all zeros, all ones) are treated as netmasks.

prefix_length

An integer vector

is_ipv6

A logical vector

Value

  • prefix_length() returns an integer vector

  • netmask() and hostmask() return an ip_address vector

See Also

Examples

x <- ip_network(c("192.168.0.0/22", "2001:db00::0/26"))

prefix_length(x)

netmask(x)

hostmask(x)

# construct netmask/hostmask from prefix length
netmask(c(22L, 26L), c(FALSE, TRUE))

hostmask(c(22L, 26L), c(FALSE, TRUE))

# extract prefix length from netmask/hostmask
prefix_length(ip_address(c("255.255.255.0", "0.255.255.255")))

# invalid netmask/hostmask raise a warning and return NA
prefix_length(ip_address("255.255.255.1"))

ipaddress

Tidy IP Addresses

v0.5.1
MIT + file LICENSE
Authors
David Hall [aut, cre] (<https://orcid.org/0000-0002-2193-0480>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.