R: Vector of IP interfaces

ip_interface {ipaddress} | R Documentation

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

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

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

    is_ip_interface(x)

    as_ip_interface(x)

    ## S3 method for class 'character'
    as_ip_interface(x)

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

    ## S3 method for class 'ip_interface'
    format(x, exploded = FALSE, ...)

### 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
`exploded` | Logical scalar. Should IPv6 addresses display leading zeros? (default: `FALSE`)

### 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("ipaddress-classes")`

### 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)

[Package ipaddress version 0.5.2 Index]