proxygen
wangle::NetworkAddress Class Reference

#include <NetworkAddress.h>

Public Member Functions

 NetworkAddress (const folly::SocketAddress &addr, unsigned prefixLen)
 
const folly::SocketAddressgetAddress () const
 
unsigned getPrefixLength () const
 
bool contains (const folly::SocketAddress &addr) const
 
bool operator< (const NetworkAddress &other) const
 
bool operator== (const NetworkAddress &other) const
 

Private Attributes

folly::SocketAddress addr_
 
unsigned prefixLen_
 

Detailed Description

A simple wrapper around SocketAddress that represents a network in CIDR notation

Definition at line 26 of file NetworkAddress.h.

Constructor & Destructor Documentation

wangle::NetworkAddress::NetworkAddress ( const folly::SocketAddress addr,
unsigned  prefixLen 
)
inline

Create a NetworkAddress for an addr/prefixLen

Parameters
addrIPv4 or IPv6 address of the network
prefixLenPrefix length, in bits

Definition at line 33 of file NetworkAddress.h.

34  :
35  addr_(addr), prefixLen_(prefixLen) {}
folly::SocketAddress addr_

Member Function Documentation

bool wangle::NetworkAddress::contains ( const folly::SocketAddress addr) const
inline

Check whether a given address lies within the network

Definition at line 46 of file NetworkAddress.h.

References addr_, prefixLen_, and folly::SocketAddress::prefixMatch().

46  {
47  return addr_.prefixMatch(addr, prefixLen_);
48  }
bool prefixMatch(const SocketAddress &other, unsigned prefixLength) const
folly::SocketAddress addr_
const folly::SocketAddress& wangle::NetworkAddress::getAddress ( ) const
inline

Get the network address

Definition at line 38 of file NetworkAddress.h.

References addr_.

38  {
39  return addr_;
40  }
folly::SocketAddress addr_
unsigned wangle::NetworkAddress::getPrefixLength ( ) const
inline

Get the prefix length in bits

Definition at line 43 of file NetworkAddress.h.

References prefixLen_.

43 { return prefixLen_; }
bool wangle::NetworkAddress::operator< ( const NetworkAddress other) const
inline

Comparison operator to enable use in ordered collections

Definition at line 51 of file NetworkAddress.h.

References addr_, and prefixLen_.

51  {
52  if (addr_ < other.addr_) {
53  return true;
54  } else if (other.addr_ < addr_) {
55  return false;
56  } else {
57  return (prefixLen_ < other.prefixLen_);
58  }
59  }
folly::SocketAddress addr_
bool wangle::NetworkAddress::operator== ( const NetworkAddress other) const
inline

Definition at line 61 of file NetworkAddress.h.

References addr_, and prefixLen_.

61  {
62  return addr_ == other.addr_ && prefixLen_ == other.prefixLen_;
63  }
folly::SocketAddress addr_

Member Data Documentation

folly::SocketAddress wangle::NetworkAddress::addr_
private

Definition at line 66 of file NetworkAddress.h.

Referenced by contains(), getAddress(), operator<(), and operator==().

unsigned wangle::NetworkAddress::prefixLen_
private

Definition at line 67 of file NetworkAddress.h.

Referenced by contains(), getPrefixLength(), operator<(), and operator==().


The documentation for this class was generated from the following file: