Crate ipnet [] [src]

Types for IPv4 and IPv6 network addresses.

This module provides types and useful methods for working with IPv4 and IPv6 network addresses, commonly called IP prefixes. The new IpNet, Ipv4Net, and Ipv6Net types build on the existing IpAddr, Ipv4Addr, and Ipv6Addr types already provided in Rust's standard library and align to their design to stay consistent.

The module also provides types for iterating over IP address ranges, and useful traits that extend Ipv4Addr and Ipv6Addr with methods for addition, subtraction, bitwise-and, and bitwise-or operations that are missing in Rust's standard library.

Organization

  • IpNet represents IP network addresses, either IPv4 or IPv6.
  • Ipv4Net and Ipv6Net are respectively IPv4 and IPv6 network addresses.
  • IpSubnets, Ipv4Subnets, and Ipv6Subnets are iterators that generate all valid IP network addresses bound by a given IP address range and minimum prefix length. These are returned by the subnets methods, but may also be used directly.
  • IpAddrRange, Ipv4AddrRange, and Ipv6AddrRange provide iteration over ranges of IP addresses. These are returned by the hosts() methods, but may also be used directly.
  • The IpAdd, IpSub, IpBitAnd, IpBitOr traits extend the Ipv4Addr and Ipv6Addr types with methods to perform these operations.
  • Emu128 is an emulated 128 bit unsigned integer implemented in this module using a struct of two u64 types. This is useful for operations on IPv6 address, which are 128 bit unsigned integers.

Structs

AddrParseError

An error which can be returned when parsing an IP network address.

Emu128

An emulated 128 bit unsigned integer.

Ipv4AddrRange

An Iterator over a range of IPv4 addresses.

Ipv4Net

An IPv4 network address.

Ipv4Subnets

An Iterator that generates IPv4 network addresses.

Ipv6AddrRange

An Iterator over a range of IPv4 or IPv6 addresses.

Ipv6Net

An IPv6 network address.

Ipv6Subnets

An Iterator that generates IPv6 network addresses.

PrefixLenError

An error that is returned when the prefix length is invalid. Valid prefix lengths are 0 to 32 for IPv4 and 0 to 128 for IPv6.

Enums

IpAddrRange

An Iterator over a range of IP addresses, either IPv4 or IPv6.

IpNet

An IP network address, either IPv4 or IPv6.

IpSubnets

An Iterator that generates IP network addresses, either IPv4 or IPv6.

Traits

Contains

Provides a contains() method to test if a network contains another network or address.

IpAdd

Provides a saturating_add() method for Ipv4Addr and Ipv6Addr.

IpBitAnd

Provides a bitand() method for Ipv4Addr and Ipv6Addr.

IpBitOr

Provides a bitor() method for Ipv4Addr and Ipv6Addr.

IpSub

Provides a saturating_sub() method for Ipv4Addr and Ipv6Addr.