44#ifndef COMMONCPP_ADDRESS_H_
45#define COMMONCPP_ADDRESS_H_
47#ifndef COMMONCPP_CONFIG_H_
48#include <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
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);
229 inline bool operator==(
const struct sockaddr *a)
const {
233 inline bool operator==(
const struct in_addr &a)
const {
237 inline bool operator!=(
const struct sockaddr *a)
const {
241 inline bool operator!=(
const struct in_addr &a)
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);
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 {
370 const InetAddrValidator *validator;
373 struct in_addr * ipaddr;
375 mutable char* hostname;
376#if defined(_MSWINDOWS_)
416 IPV4Address(
struct in_addr addr,
const InetAddrValidator *validator = NULL);
428 IPV4Address(
const char *address,
const InetAddrValidator *validator = NULL);
464 struct in_addr getAddress(void) const;
477 struct in_addr getAddress(size_t i) const;
496 inline operator bool()
const {
497 return isInetAddress();
500 inline bool operator!()
const {
501 return !isInetAddress();
567 return IPV4Address::operator =(addr);
612 return IPV4Address::operator =(addr);
690extern __EXPORT std::ostream& operator<<(std::ostream &os,
const IPV4Address &ia);
692inline struct in_addr getaddress(const
IPV4Address &ia) {
693 return ia.getAddress();
788 struct in6_addr * ipaddr;
790 mutable char* hostname;
791#if defined(_MSWINDOWS_)
879 struct in6_addr getAddress(void) const;
892 struct in6_addr getAddress(size_t i) const;
907 inline operator bool ()
const {
908 return isInetAddress();
911 inline bool operator!()
const {
912 return !isInetAddress();
1082extern __EXPORT std::ostream& operator<<(std::ostream &os,
const IPV6Address &ia);
1084inline struct in6_addr getaddress(const
IPV6Address &ia) {
1085 return ia.getAddress();
GNU Common C++ exception model base classes.
in_port_t tpport_t
Transport Protocol Ports.
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.
Class for the function object that validates multicast addresses.
virtual ~IPV4MulticastValidator()
Keeps compilers happy.
IPV4MulticastValidator()
Constructor.
void operator()(const in_addr address) const
Application operator.
The CIDR class is used to support routing tables and validate address policies.
IPV4Cidr(IPV4Cidr &)
Construct a copy of a cidr.
void set(const char *cidr)
Set the cidr from a full or partial hostname, or from an address/mask, or a host/bits specification.
IPV4Cidr()
Construct an empty cidr.
bool isMember(const struct sockaddr *saddr) const
See if a socket address is a member of this cidr's network.
IPV4Cidr(const char *cidr)
Construct a new cidr from a string.
bool isMember(const struct in_addr &inaddr) const
See if a low level address object is a member of this cidr's net.
The CIDR class is used to support routing tables and validate address policies.
bool isMember(const struct in6_addr &inaddr) const
See if a low level address object is a member of this cidr's net.
void set(const char *cidr)
Set the cidr from a full or partial hostname, or from a host/bits specification.
bool isMember(const struct sockaddr *saddr) const
See if a socket address is a member of this cidr's network.
IPV6Cidr()
Construct an empty cidr.
IPV6Cidr(const char *cidr)
Construct a new cidr from a string.
IPV6Cidr(IPV6Cidr &)
Construct a copy of a cidr.
The network name and address objects are all derived from a common IPV4Address base class.
IPV4Address(const IPV4Validator *validator=NULL)
Create an Internet Address object with an empty (0.0.0.0) address.
IPV4Address(struct in_addr addr, const IPV4Validator *validator=NULL)
Convert the system internet address data type (struct in_addr) into a Common C++ IPV4Address object.
void setAddress(const char *host)
Used to specify a host name or numeric internet address.
const char * getHostname(void) const
Provide a string representation of the value (Internet Address) held in the IPV4Address object.
IPV4Address & operator=(in_addr_t addr)
Allows assignment from the return of functions like inet_addr() or htonl()
bool operator!=(const IPV4Address &a) const
Compare two internet addresses to see if they are not equal (if they each refer to unique and differe...
bool isInetAddress(void) const
May be used to verify if a given IPV4Address returned by another function contains a "valid" address,...
bool setIPAddress(const char *host)
Sets the IP address from a string representation of the numeric address, ie "127.0....
bool operator==(const IPV4Address &a) const
Compare two internet addresses to see if they are equal (if they specify the physical address of the ...
IPV4Address(const char *address, const IPV4Validator *validator=NULL)
Convert a null terminated ASCII host address string (example: "127.0.0.1") or host address name (exam...
size_t getAddressCount() const
Returns the number of internet addresses that an IPV4Address object contains.
virtual ~IPV4Address()
Destructor.
IPV4Address(const IPV4Address &rhs)
Copy constructor.
Internet addresses used specifically as masking addresses (such as "255.255.255.0") are held in the I...
friend IPV4Host operator&(const IPV4Host &addr, const IPV4Mask &mask)
Masks are usually used to coerce host addresses into a specific router or class domain.
IPV4Address & operator=(in_addr_t addr)
Allows assignment from the return of functions like inet_addr() or htonl()
IPV4Mask(const char *mask)
Create the mask from a null terminated ASCII string such as "255.255.255.128".
This object is used to hold the actual and valid internet address of a specific host machine that wil...
IPV4Host & operator&=(const IPV4Mask &mask)
Mask the internet host address object with a network mask address.
IPV4Host(struct in_addr addr)
Convert a system socket binary address such as may be returned through the accept() call or getsockpe...
IPV4Host(const char *host=NULL)
Create a new host address for a specific internet host.
IPV4Address & operator=(in_addr_t addr)
Allows assignment from the return of functions like inet_addr() or htonl()
The broadcast address object is used to store the broadcast address for a specific subnet.
IPV4Broadcast(const char *net="255.255.255.255")
Specify the physical broadcast address to use and create a new broadcast address object based on a nu...
A specialization of IPV4Address that provides address validation for multicast addresses.
IPV4Multicast(const char *address)
Convert a null terminated ASCII multicast address string (example: "224.0.0.1") or multicast name str...
IPV4Multicast()
Create an Internet Multicast Address object with an empty (0.0.0.0) address.
IPV4Multicast(const struct in_addr address)
Convert the system internet address data type (struct in_addr) into a Common C++ IPV4Multicast object...
Classes derived from IPV6Address would require an specific validator to pass to the IPV6Address const...
virtual ~IPV6Validator()
Keeps compilers happy.
IPV6Validator()
Constructor.
virtual void operator()(const in6_addr address) const =0
Pure virtual application operator.
Class for the function object that validates multicast addresses.
void operator()(const in6_addr address) const
Application operator.
virtual ~IPV6MulticastValidator()
Keeps compilers happy...
IPV6MulticastValidator()
Constructor.
The network name and address objects are all derived from a common IPV6Address base class.
bool operator==(const IPV6Address &a) const
Compare two internet addresses to see if they are equal (if they specify the physical address of the ...
bool operator!=(const IPV6Address &a) const
Compare two internet addresses to see if they are not equal (if they each refer to unique and differe...
IPV6Address(const IPV6Validator *validator=NULL)
Create an Internet Address object with an empty (0.0.0.0) address.
bool isInetAddress(void) const
May be used to verify if a given IPV6Address returned by another function contains a "valid" address,...
const char * getHostname(void) const
Provide a string representation of the value (Internet Address) held in the IPV6Address object.
void setAddress(const char *host)
Used to specify a host name or numeric internet address.
IPV6Address(struct in6_addr addr, const IPV6Validator *validator=NULL)
Convert the system internet address data type (struct in_addr) into a Common C++ IPV6Address object.
virtual ~IPV6Address()
Destructor.
size_t getAddressCount() const
Returns the number of internet addresses that an IPV6Address object contains.
IPV6Address(const IPV6Address &rhs)
Copy constructor.
IPV6Address(const char *address, const IPV6Validator *validator=NULL)
Convert a null terminated ASCII host address string (example: "127.0.0.1") or host address name (exam...
bool setIPAddress(const char *host)
Sets the IP address from a string representation of the numeric address, ie "127.0....
Internet addresses used specifically as masking addresses (such as "255.255.255.0") are held in the I...
IPV6Mask(const char *mask)
Create the mask from a null terminated ASCII string such as "255.255.255.128".
friend IPV6Host operator&(const IPV6Host &addr, const IPV6Mask &mask)
Masks are usually used to coerce host addresses into a specific router or class domain.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
IPV6Host(const char *host=NULL)
Create a new host address for a specific internet host.
IPV6Host(struct in6_addr addr)
Convert a system socket binary address such as may be returned through the accept() call or getsockpe...
IPV6Host & operator&=(const IPV6Mask &mask)
Mask the internet host address object with a network mask address.
The broadcast address object is used to store the broadcast address for a specific subnet.
IPV6Broadcast(const char *net="255.255.255.255")
Specify the physical broadcast address to use and create a new broadcast address object based on a nu...
A specialization of IPV6Address that provides address validation for multicast addresses.
IPV6Multicast(const char *address)
Convert a null terminated ASCII multicast address string (example: "224.0.0.1") or multicast name str...
IPV6Multicast(const struct in6_addr address)
Convert the system internet address data type (struct in_addr) into a Common C++ IPV4Multicast object...
IPV6Multicast()
Create an Internet Multicast Address object with an empty (0.0.0.0) address.
The Mutex Counter is a counter variable which can safely be incremented or decremented by multiple th...
Common C++ thread class and sychronization objects.