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"))
Run the code above in your browser using DataLab