#535 Missing methods in IPAddress

Feature_Request
closed
nobody
Net (141)
5
2012-12-12
2012-06-26
No

IPAddress is missing a constructor as:

IPAddress(IPAddress::Family family, unsigned prefixlen);

which creates a netmask IPAddress, and:

const IPAddress& operator~();

which takes an IPAddress (typically a netmask), and inverts all of the bits.

This would permit, for instance:

    IPAddress dst;
    unsigned prefix;
    ...
    // check for bits in complement of mask
    if (dst & ~Net::IPAddress(dst.family(), prefix) != Net::IPAddress::wildcard(dst.family()))
                  throw std::invalid_argument("Prefix disagrees with destination length");

if one wanted to validate a subnet address and matching prefix length, for instance, by making sure that only bits that fell inside the prefix were set.

Discussion

  • To this, I'd also add a method that, given an IPAddress, returns the prefixlen that corresponds to that (keep in mind that there are braindead people out there still using non-contiguous netmasks).

     
  • Actually, adding the operators: '&', '|', '^', and '~' would be good, then the mask() functions could either be deprecated or implemented as inline wrappers using this methods.

     
  • Alex Fabijanic
    Alex Fabijanic
    2012-12-12

    • status: open --> closed
     
  • Alex Fabijanic
    Alex Fabijanic
    2012-12-12

    done in 1.5.0. closing