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
80 typedef unsigned short tpport_t;
110 operator()(
const in_addr address)
const = 0;
151 struct in_addr netmask, network;
153 unsigned getMask(
const char *cp)
const;
160 inline struct in_addr getNetwork(void) const
168 inline struct in_addr getNetmask(void) const
176 struct in_addr getBroadcast(void) const;
184 void set(
const char *cidr);
211 bool isMember(
const struct sockaddr *saddr)
const;
219 bool isMember(
const struct in_addr &inaddr)
const;
221 inline bool operator==(
const struct sockaddr *a)
const
222 {
return isMember(a);};
224 inline bool operator==(
const struct in_addr &a)
const
225 {
return isMember(a);};
239 struct in6_addr netmask, network;
241 unsigned getMask(
const char *cp)
const;
248 inline struct in6_addr getNetwork(void) const
256 inline struct in6_addr getNetmask(void) const
264 struct in6_addr getBroadcast(void) const;
272 void set(
const char *cidr);
299 bool isMember(
const struct sockaddr *saddr)
const;
307 bool isMember(
const struct in6_addr &inaddr)
const;
309 inline bool operator==(
const struct sockaddr *sa)
const
310 {
return isMember(sa);};
312 inline bool operator==(
const struct in6_addr &a)
const
313 {
return isMember(a);};
340 const InetAddrValidator *validator;
343 struct in_addr * ipaddr;
345 mutable char* hostname;
346 #if defined(_MSWINDOWS_)
358 bool setIPAddress(
const char *host);
366 void setAddress(
const char *host);
376 IPV4Address(
const InetAddrValidator *validator = NULL);
386 IPV4Address(
struct in_addr
addr,
const InetAddrValidator *validator = NULL);
398 IPV4Address(
const char *address,
const InetAddrValidator *validator = NULL);
416 const char *getHostname(
void)
const;
425 bool isInetAddress(
void)
const;
434 struct in_addr getAddress(void) const;
447 struct in_addr getAddress(size_t i) const;
467 {
return *
this = (
unsigned long) addr; }
469 inline bool operator!()
const
470 {
return !isInetAddress();};
480 bool operator==(
const IPV4Address &a)
const;
489 bool operator!=(
const IPV4Address &a)
const;
533 {
return IPV4Address::operator =(addr); }
577 {
return IPV4Address::operator =(addr); }
657 inline struct in_addr getaddress(const
IPV4Address &ia)
658 {
return ia.getAddress();}
690 virtual void operator()(
const in6_addr address)
const = 0;
718 void operator()(
const in6_addr address)
const;
746 struct in6_addr * ipaddr;
748 mutable char* hostname;
749 #if defined(_MSWINDOWS_)
761 bool setIPAddress(
const char *host);
769 void setAddress(
const char *host);
819 const char *getHostname(
void)
const;
828 bool isInetAddress(
void)
const;
837 struct in6_addr getAddress(void) const;
850 struct in6_addr getAddress(size_t i) const;
863 inline bool operator!()
const
864 {
return !isInetAddress();};
874 bool operator==(
const IPV6Address &a)
const;
883 bool operator!=(
const IPV6Address &a)
const;
1033 inline struct in6_addr getaddress(const
IPV6Address &ia)
1034 {
return ia.getAddress();}