ip_interface: Vector of IP interfaces

View source: R/ip_interface.R

ip_interfaceR Documentation

Vector of IP interfaces

Description

Construct a vector of IP interfaces.

This hybrid class stores both the host address and the network it is on.

Usage

ip_interface(...)

## Default S3 method:
ip_interface(x = character(), ...)

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

Arguments

...

Arguments passed to methods.

x

A character vector of IP interfaces, in CIDR notation (IPv4 or IPv6)

address

An ip_address vector

prefix_length

An integer vector

Details

Constructing an ip_interface vector is conceptually like constructing an ip_network vector, except the host bits are retained.

The ip_interface class inherits from the ip_address class. This means it can generally be used in places where an ip_address vector is expected. A few exceptions to this rule are:

  • It does not support addition and subtraction of integers

  • It does not support bitwise operations

  • It cannot be compared to ip_address vectors

The ip_interface class additionally supports a few functions typically reserved for ip_network vectors: prefix_length(), netmask() and hostmask().

For other purposes, you can extract the address and network components using as_ip_address() and as_ip_network().

When comparing and sorting ip_interface vectors, the network is compared before the host address.

Value

An S3 vector of class ip_interface

See Also

vignette("ip-data")

Examples

# construct from character vector
ip_interface(c("192.168.0.1/10", "2001:db8:c3::abcd/45"))

# construct from address + prefix length objects
ip_interface(ip_address(c("192.168.0.1", "2001:db8:c3::abcd")), c(10L, 45L))

# extract IP address
x <- ip_interface(c("192.168.0.1/10", "2001:db8:c3::abcd/45"))
as_ip_address(x)

# extract IP network (with host bits masked)
as_ip_network(x)

ipaddress documentation built on April 4, 2023, 9:09 a.m.