44#ifndef COMMONCPP_ADDRESS_H_
45#define COMMONCPP_ADDRESS_H_
47#ifndef COMMONCPP_CONFIG_H_
51#ifndef COMMONCPP_THREAD_H_
55#ifndef COMMMONCPP_EXCEPTION_H_
63#define INET_IPV4_ADDRESS_SIZE 16
64#define CIDR_IPV4_ADDRESS_SIZE 32
65#define INET_IPV6_ADDRESS_SIZE 40
66#define CIDR_IPV6_ADDRESS_SIZE 45
69#define InetAddress IPV4Address
70#define InetHostAddress IPV4Host
71#define InetMaskAddress IPV4Mask
72#define InetMcastAddress IPV4Multicast
73#define InetMcastAddressValidator IPV4MulticastValidator
74#define InetAddrValidator IPV4Validator
75#define BroadcastAddress IPV4Broadcast
144 void operator()(
const in_addr address)
const __OVERRIDE;
157 struct in_addr netmask, network;
159 unsigned getMask(
const char *cp)
const;
166 inline struct in_addr getNetwork(void) const {
175 inline struct in_addr getNetmask(void) const {
184 struct in_addr getBroadcast(void) const;
192 void set(
const char *
cidr);
219 bool isMember(
const struct sockaddr *saddr)
const;
227 bool isMember(
const struct in_addr &inaddr)
const;
257 struct in6_addr netmask, network;
259 unsigned getMask(
const char *cp)
const;
266 inline struct in6_addr getNetwork(void) const {
275 inline struct in6_addr getNetmask(void) const {
284 struct in6_addr getBroadcast(void) const;
292 void set(
const char *cidr);
299 IPV6Cidr(
const char *cidr);
311 IPV6Cidr(IPV6Cidr &);
319 bool isMember(
const struct sockaddr *saddr)
const;
327 bool isMember(
const struct in6_addr &inaddr)
const;
329 inline bool operator==(
const struct sockaddr *sa)
const {
333 inline bool operator==(
const struct in6_addr &a)
const {
337 inline bool operator!=(
const struct sockaddr *sa)
const {
338 return !isMember(sa);
341 inline bool operator!=(
const struct in6_addr &a)
const {
376#if defined(_MSWINDOWS_)
388 bool setIPAddress(
const char *host);
396 void setAddress(
const char *host);
446 const char *getHostname(
void)
const;
455 bool isInetAddress(
void)
const;
464 struct in_addr getAddress(void) const;
477 struct in_addr getAddress(size_t i) const;
496 inline operator bool()
const {
497 return isInetAddress();
501 return !isInetAddress();
567 return IPV4Address::operator =(
addr);
612 return IPV4Address::operator =(
addr);
693 return ia.getAddress();
723 virtual ~IPV6Validator() {}
729 virtual void operator()(
const in6_addr address)
const = 0;
740class __EXPORT IPV6MulticastValidator:
public IPV6Validator
749 IPV6MulticastValidator(){}
754 virtual ~IPV6MulticastValidator(){}
760 void operator()(
const in6_addr address)
const __OVERRIDE;
785 const IPV6Validator *validator;
788 struct in6_addr * ipaddr;
790 mutable char* hostname;
791#if defined(_MSWINDOWS_)
792 static MutexCounter counter;
803 bool setIPAddress(
const char *host);
811 void setAddress(
const char *host);
821 IPV6Address(
const IPV6Validator *validator = NULL);
831 IPV6Address(
struct in6_addr addr,
const IPV6Validator *validator = NULL);
843 IPV6Address(
const char *address,
const IPV6Validator *validator = NULL);
848 IPV6Address(
const IPV6Address &rhs);
853 virtual ~IPV6Address();
861 const char *getHostname(
void)
const;
870 bool isInetAddress(
void)
const;
879 struct in6_addr getAddress(void) const;
892 struct in6_addr getAddress(size_t i) const;
899 size_t getAddressCount()
const {
903 IPV6Address &operator=(
const char *str);
904 IPV6Address &operator=(
struct in6_addr addr);
905 IPV6Address &operator=(
const IPV6Address &rhs);
907 inline operator bool ()
const {
908 return isInetAddress();
911 inline bool operator!()
const {
912 return !isInetAddress();
923 bool operator==(
const IPV6Address &a)
const;
932 bool operator!=(
const IPV6Address &a)
const;
947class __EXPORT IPV6Mask :
public IPV6Address
959 IPV6Mask(
const char *mask);
981class __EXPORT IPV6Host :
public IPV6Address
996 IPV6Host(
const char *host = NULL);
1005 IPV6Host(
struct in6_addr addr);
1011 IPV6Host &operator&=(
const IPV6Mask &mask);
1013 friend class IPV6Mask;
1021class __EXPORT IPV6Broadcast :
public IPV6Address
1031 IPV6Broadcast(
const char *net =
"255.255.255.255");
1043class __EXPORT IPV6Multicast:
public IPV6Address
1058 IPV6Multicast(
const struct in6_addr address);
1069 IPV6Multicast(
const char *address);
1079 static const IPV6MulticastValidator validator;
1084inline struct in6_addr
getaddress(const IPV6Address &ia) {
1085 return ia.getAddress();
#define InetAddrValidator
The network name and address objects are all derived from a common IPV4Address base class.
const IPV4Validator * validator
size_t getAddressCount() const
Returns the number of internet addresses that an IPV4Address object contains.
The broadcast address object is used to store the broadcast address for a specific subnet.
The CIDR class is used to support routing tables and validate address policies.
bool operator!=(const struct sockaddr *a) const
bool operator==(const struct in_addr &a) const
bool operator==(const struct sockaddr *a) const
bool operator!=(const struct in_addr &a) const
This object is used to hold the actual and valid internet address of a specific host machine that wil...
IPV4Address & operator=(in_addr_t addr)
Allows assignment from the return of functions like inet_addr() or htonl()
Internet addresses used specifically as masking addresses (such as " 255.255.255.0") are held in the ...
IPV4Address & operator=(in_addr_t addr)
Allows assignment from the return of functions like inet_addr() or htonl()
Class for the function object that validates multicast addresses.
virtual ~IPV4MulticastValidator()
Keeps compilers happy.
__DELETE_COPY(IPV4MulticastValidator)
IPV4MulticastValidator()
Constructor.
A specialization of IPV4Address that provides address validation for multicast addresses.
static const IPV4MulticastValidator validator
Check the address in addr is a valid multicast address.
Classes derived from IPV4Address would require an specific validator to pass to the IPV4Address const...
virtual ~IPV4Validator()
keeps compilers happy.
virtual void operator()(const in_addr address) const =0
Pure virtual application operator.
IPV4Validator()
Constructor.
__DELETE_COPY(IPV4Validator)
The Mutex Counter is a counter variable which can safely be incremented or decremented by multiple th...
A class to hold internet segment routing rules.
Automatic integer counting class.
Common C++ thread class and sychronization objects.
GNU Common C++ exception model base classes.
struct in_addr getaddress(const IPV4Address &ia)
in_port_t tpport_t
Transport Protocol Ports.
IPV4Host operator&(const IPV4Host &addr, const IPV4Mask &mask)
ostream & operator<<(ostream &os, const IPV4Address &ia)
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.