44 #ifndef CCXX_ADDRESS_H_
45 #define CCXX_ADDRESS_H_
47 #ifndef CCXX_CONFIG_H_
48 #include <cc++/config.h>
51 #ifndef CCXX_MISSING_H_
55 #ifndef CCXX_THREAD_H_
59 #ifndef CCXX_EXCEPTION_H_
63 #ifdef CCXX_NAMESPACES
69 #define INET_IPV4_ADDRESS_SIZE 16
70 #define CIDR_IPV4_ADDRESS_SIZE 32
71 #define INET_IPV6_ADDRESS_SIZE 40
72 #define CIDR_IPV6_ADDRESS_SIZE 45
75 #define InetAddress IPV4Address
76 #define InetHostAddress IPV4Host
77 #define InetMaskAddress IPV4Mask
78 #define InetMcastAddress IPV4Multicast
79 #define InetMcastAddressValidator IPV4MulticastValidator
80 #define InetAddrValidator IPV4Validator
81 #define BroadcastAddress IPV4Broadcast
116 operator()(
const in_addr address)
const = 0;
144 void operator()(
const in_addr address)
const;
146 #if __BYTE_ORDER == __BIG_ENDIAN
148 MCAST_VALID_MASK = 0xF0000000,
149 MCAST_VALID_VALUE = 0xE0000000
153 MCAST_VALID_MASK = 0x000000F0,
154 MCAST_VALID_VALUE = 0x000000E0
169 struct in_addr netmask, network;
171 unsigned getMask(
const char *cp)
const;
178 inline struct in_addr getNetwork(void) const
186 inline struct in_addr getNetmask(void) const
194 struct in_addr getBroadcast(void) const;
202 void set(
const char *cidr);
229 bool isMember(
const struct sockaddr *saddr)
const;
237 bool isMember(
const struct in_addr &inaddr)
const;
240 {
return isMember(a);};
243 {
return isMember(a);};
257 struct in6_addr netmask, network;
259 unsigned getMask(
const char *cp)
const;
266 inline struct in6_addr getNetwork(void) const
274 inline struct in6_addr getNetmask(void) const
282 struct in6_addr getBroadcast(void) const;
290 void set(
const char *cidr);
297 IPV6Cidr(
const char *cidr);
309 IPV6Cidr(IPV6Cidr &);
317 bool isMember(
const struct sockaddr *saddr)
const;
325 bool isMember(
const struct in6_addr &inaddr)
const;
327 inline bool operator==(
const struct sockaddr *sa)
const
328 {
return isMember(sa);};
330 inline bool operator==(
const struct in6_addr &a)
const
331 {
return isMember(a);};
376 bool setIPAddress(
const char *host);
384 void setAddress(
const char *host);
434 const char *getHostname(
void)
const;
443 bool isInetAddress(
void)
const;
452 struct in_addr getAddress(void) const;
465 struct in_addr getAddress(size_t i) const;
485 {
return *
this = (
unsigned long) addr; }
488 {
return !isInetAddress();};
676 {
return ia.getAddress();}
702 virtual ~IPV6Validator() {};
708 virtual void operator()(
const in6_addr address)
const = 0;
719 class __EXPORT IPV6MulticastValidator:
public IPV6Validator
725 IPV6MulticastValidator(){};
730 virtual ~IPV6MulticastValidator(){};
736 void operator()(
const in6_addr address)
const;
761 const IPV6Validator *validator;
764 struct in6_addr * ipaddr;
766 mutable char* hostname;
779 bool setIPAddress(
const char *host);
787 void setAddress(
const char *host);
797 IPV6Address(
const IPV6Validator *validator = NULL);
807 IPV6Address(
struct in6_addr addr,
const IPV6Validator *validator = NULL);
819 IPV6Address(
const char *address,
const IPV6Validator *validator = NULL);
824 IPV6Address(
const IPV6Address &rhs);
829 virtual ~IPV6Address();
837 const char *getHostname(
void)
const;
846 bool isInetAddress(
void)
const;
855 struct in6_addr getAddress(void) const;
868 struct in6_addr getAddress(size_t i) const;
875 size_t getAddressCount()
const {
return addr_count; }
877 IPV6Address &operator=(
const char *str);
878 IPV6Address &operator=(
struct in6_addr addr);
879 IPV6Address &operator=(
const IPV6Address &rhs);
881 inline bool operator!()
const
882 {
return !isInetAddress();};
892 bool operator==(
const IPV6Address &a)
const;
901 bool operator!=(
const IPV6Address &a)
const;
916 class __EXPORT IPV6Mask :
public IPV6Address
925 IPV6Mask(
const char *mask);
937 friend __EXPORT IPV6Host operator&(
const IPV6Host &addr,
938 const IPV6Mask &mask);
948 class __EXPORT IPV6Host :
public IPV6Address
963 IPV6Host(
const char *host = NULL);
972 IPV6Host(
struct in6_addr addr);
978 IPV6Host &operator&=(
const IPV6Mask &mask);
981 friend __EXPORT IPV6Host operator&(
const IPV6Host &addr,
const IPV6Mask &mask);
988 class __EXPORT IPV6Broadcast :
public IPV6Address
998 IPV6Broadcast(
const char *net =
"255.255.255.255");
1010 class __EXPORT IPV6Multicast:
public IPV6Address
1025 IPV6Multicast(
const struct in6_addr address);
1036 IPV6Multicast(
const char *address);
1046 static const IPV6MulticastValidator validator;
1051 inline struct in6_addr
getaddress(const IPV6Address &ia)
1052 {
return ia.getAddress();}
1057 #ifdef CCXX_NAMESPACES
virtual ~IPV4MulticastValidator()
Keeps compilers happy.
IPV4Address & operator=(const char *str)
Internet addresses used specifically as masking addresses (such as " 255.255.255.0") are held in the ...
unsigned short tpport_t
Transport Protocol Ports.
substitute functions which may be missing in target platform libc.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
IPV4Address & operator=(unsigned int addr)
GNU Common C++ exception model base classes.
The Mutex Counter is a counter variable which can safely be incremented or decremented by multiple th...
Synchronization and threading services.
The broadcast address object is used to store the broadcast address for a specific subnet...
__EXPORT std::ostream & operator<<(std::ostream &os, const IPV4Address &ia)
Classes derived from IPV4Address would require an specific validator to pass to the IPV4Address const...
static const IPV4MulticastValidator validator
Check the address in addr is a valid multicast address.
IPV4Address & operator=(unsigned long addr)
Allows assignment from the return of functions like inet_addr() or htonl()
bool operator==(const struct sockaddr *a) const
size_t getAddressCount() const
Returns the number of internet addresses that an IPV4Address object contains.
Class for the function object that validates multicast addresses.
IPV4MulticastValidator()
Constructor.
bool operator==(const struct in_addr &a) const
struct in_addr getaddress(const IPV4Address &ia)
virtual ~IPV4Validator()
keeps compilers happy.
IPV4Validator()
Constructor.
A specialization of IPV4Address that provides address validation for multicast addresses.
The CIDR class is used to support routing tables and validate address policies.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
The network name and address objects are all derived from a common IPV4Address base class...
const IPV4Validator * validator
#define InetAddrValidator
IPV4Address & operator=(unsigned long addr)
Allows assignment from the return of functions like inet_addr() or htonl()