ipnet 0.26.1

Provides types and methods for working with IPv4 and IPv6 network addresses, commonly called IP prefixes. Uses only stable Rust features and aligns to the standard library IpAddr, Ipv4Addr, and Ipv6Addr types. Nearing 1.0 release, reviews very welcome.
Documentation

Nearing 1.0 release, reviews very welcome.

This module provides types and methods for working with IPv4 and IPv6 network addresses, commonly called IP prefixes. It only uses stable Rust features so it compiles using the stable toolchain. And its design aligns to the existing IpAddr, Ipv4Addr, and Ipv6Addr types provided in the Rust standard library.

The module includes extension traits to provide Add, Sub, BitAnd, and BitOr operations to Ipv4Addr and Ipv6Addr.

See Crates.io and the documentation for more information.

TODO / Open Questions:

  • Should new() truncate the input Ipv4Addr to the prefix_len and store that instead? Technically it doesn't matter, but users may expect one behavior over the other. At the moment there is a trunc() method that does this.
  • Should new() precompute the netmask, hostmask, network, and broadcast addresses and store these to avoid recomputing everytime the methods are called? This would quadruple the size of the type, it doesn't seem beneficial enough.
  • Can we implement the std::ops::{Add, Sub, BitAnd, BitOr} traits for Ipv4Addr and Ipv6Addr in the standard library? These are common operations on IP addresses. I've started a thread on this over here: https://internals.rust-lang.org/t/pre-rfc-implementing-add-sub-bitand-bitor-for-ipaddr-ipv4addr-ipv6addr/

Future

  • Explore representing the results of methods such as hosts() and subnets() as a Range. This requires both the Add and Step traits be implemented on the target type. For the three IpAddr types implementing Add must be done through an enhancement to the standard library. For all types, using Step means we must use nightly because it is not yet stable. This crate only uses stable Rust features.

Legal

Copyright (c) 2017, Juniper Networks, Inc. All rights reserved.

This code is licensed to you under the Apache License, Version 2.0 (the "License"). You may not use this code except in compliance with the License. This code is not an official Juniper product. You can obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0