Learn R Programming

ipaddress (version 0.3.0)

ip_interface: Vector of IP interfaces

Description

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

ip_interface() constructs a vector of IP interfaces.

is_ip_interface() checks if an object is of class ip_interface.

as_ip_interface() casts an object to ip_interface.

Usage

ip_interface(...)

# S3 method for default ip_interface(x = character(), ...)

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

is_ip_interface(x)

as_ip_interface(x)

# S3 method for character as_ip_interface(x)

# S3 method for ip_interface as.character(x, ...)

# S3 method for ip_interface format(x, ...)

Arguments

...

Included for S3 generic consistency

x
  • For ip_interface(): A character vector of IP interfaces, in CIDR notation (IPv4 or IPv6)

  • For is_ip_interface(): An object to test

  • For as_ip_interface(): An object to cast

  • For as.character(): An ip_interface vector

address

An ip_address vector

prefix_length

An integer vector

Value

An S3 vector of class ip_interface

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().

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab