Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

address.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // Common C++.  If you copy code from other releases into a copy of GNU
00028 // Common C++, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU Common C++, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00043 #ifndef CCXX_ADDRESS_H_
00044 #define CCXX_ADDRESS_H_
00045 
00046 #ifndef CCXX_MISSING_H_
00047 #include <cc++/missing.h>
00048 #endif
00049 
00050 #ifndef CCXX_THREAD_H_
00051 #include <cc++/thread.h>
00052 #endif
00053 
00054 #ifndef CCXX_EXCEPTION_H_
00055 #include <cc++/exception.h>
00056 #endif
00057 
00058 #if defined(WIN32) && !defined(__CYGWIN32__)
00059 #define __WINSOCK__
00060 #include <winsock2.h>
00061 #endif
00062 
00063 #ifdef  CCXX_NAMESPACES
00064 namespace ost {
00065 #endif
00066 
00067 // future definition of ipv4 specific classes, now defines
00068 
00069 #define InetAddress     IPV4Address
00070 #define InetHostAddress IPV4Host
00071 #define InetMaskAddress IPV4Mask
00072 #define InetMcastAddress IPV4Multicast
00073 #define InetMcastAddressValidator IPV4MulticastValidator
00074 #define InetAddrValidator IPV4Validator
00075 #define BroadcastAddress IPV4Broadcast
00076 
00080 typedef unsigned short tpport_t;
00081 
00082 class __EXPORT IPV4Host;
00083 
00092 class __EXPORT IPV4Validator 
00093 {
00094 public:
00098         IPV4Validator() { };
00099 
00104         virtual void 
00105         operator()(const in_addr address) const = 0;
00106 };
00107 
00116 class __EXPORT IPV4MulticastValidator: public IPV4Validator
00117 {
00118 public:
00122         IPV4MulticastValidator(){};
00123 
00128         void operator()(const in_addr address) const; 
00129 private:
00130 #if __BYTE_ORDER == __BIG_ENDIAN
00131         enum {
00132                 MCAST_VALID_MASK = 0xF0000000,
00133                 MCAST_VALID_VALUE = 0xE0000000
00134         };
00135 #else
00136         enum { 
00137                 MCAST_VALID_MASK = 0x000000F0,
00138                 MCAST_VALID_VALUE = 0x000000E0 
00139         };
00140 #endif
00141 };
00142 
00157 class __EXPORT IPV4Address
00158 {
00159 private:
00160         // The validator given to an IPV4Address object must not be a
00161         // transient object, but that must exist at least until the
00162         // last address object of its kind is deleted. This is an
00163         // artifact to be able to do specific checks for derived
00164         // classes inside constructors.
00165         const InetAddrValidator *validator;
00166 
00167 protected:
00168         struct in_addr * ipaddr;
00169         size_t addr_count;
00170         mutable char* hostname;  // hostname for ipaddr[0]. Used by getHostname
00171 #if defined(WIN32)
00172         static MutexCounter counter;
00173 #else
00174         static Mutex mutex;
00175 #endif
00176 
00183         bool setIPAddress(const char *host);
00184 
00191         void setAddress(const char *host);
00192 
00193 public:
00201         IPV4Address(const InetAddrValidator *validator = NULL);
00202 
00211         IPV4Address(struct in_addr addr, const InetAddrValidator *validator = NULL);
00212 
00223         IPV4Address(const char *address, const InetAddrValidator *validator = NULL);
00224 
00228         IPV4Address(const IPV4Address &rhs);
00229 
00233         virtual ~IPV4Address();
00234 
00241         const char *getHostname(void) const;
00242 
00250         bool isInetAddress(void) const;
00251 
00259         struct in_addr getAddress(void) const;
00260 
00272         struct in_addr getAddress(size_t i) const;
00273 
00279         size_t getAddressCount() const { return addr_count; }
00280 
00281         IPV4Address &operator=(const char *str);
00282         IPV4Address &operator=(struct in_addr addr);
00283         IPV4Address &operator=(const IPV4Address &rhs);
00284 
00289         IPV4Address &operator=(unsigned long addr);
00290 
00291         inline IPV4Address &operator=(unsigned int addr)
00292                 {return *this = (unsigned long) addr; }
00293 
00294         inline bool operator!() const
00295                 {return !isInetAddress();};
00296 
00305         bool operator==(const IPV4Address &a) const;
00306 
00314         bool operator!=(const IPV4Address &a) const;
00315 };      
00316 
00329 class __EXPORT IPV4Mask : public IPV4Address
00330 {
00331 public:
00338         IPV4Mask(const char *mask);
00339 
00350         friend __EXPORT IPV4Host operator&(const IPV4Host &addr, 
00351                                          const IPV4Mask &mask);
00352 
00357         IPV4Address &operator=(unsigned long addr) 
00358                 { return IPV4Address::operator =(addr); }
00359 };
00360 
00368 class __EXPORT IPV4Host : public IPV4Address
00369 {
00370 public: 
00383         IPV4Host(const char *host = NULL);
00384 
00392         IPV4Host(struct in_addr addr);
00393 
00398         IPV4Address &operator=(unsigned long addr) 
00399         { return IPV4Address::operator =(addr); }
00400 
00405         IPV4Host &operator&=(const IPV4Mask &mask);
00406 
00407         friend class __EXPORT IPV4Mask;
00408         friend __EXPORT IPV4Host operator&(const IPV4Host &addr, 
00409                                          const IPV4Mask &mask);
00410 };
00411 
00416 class __EXPORT IPV4Broadcast : public IPV4Address
00417 {
00418 public:
00426         IPV4Broadcast(const char *net = "255.255.255.255");
00427 };
00428 
00438 class __EXPORT IPV4Multicast: public IPV4Address
00439 {
00440 public:
00445         IPV4Multicast();
00446 
00453         IPV4Multicast(const struct in_addr address);
00454 
00464         IPV4Multicast(const char *address);
00465         
00466 private:
00474         static const IPV4MulticastValidator validator;
00475 };
00476 
00477 extern __EXPORT std::ostream& operator<<(std::ostream &os, const IPV4Address &ia);
00478 
00479 inline struct in_addr getaddress(const IPV4Address &ia)
00480         {return ia.getAddress();}
00481 
00482 
00483 #ifdef  CCXX_IPV6
00484 
00485 class __EXPORT IPV6Host;
00486 
00495 class __EXPORT IPV6Validator 
00496 {
00497 public:
00501         IPV6Validator() { };
00502 
00507         virtual void 
00508         operator()(const in6_addr address) const = 0;
00509 };
00510 
00519 class __EXPORT IPV6MulticastValidator: public IPV6Validator
00520 {
00521 public:
00525         IPV6MulticastValidator(){};
00526 
00531         void operator()(const in6_addr address) const; 
00532 };
00533 
00548 class __EXPORT IPV6Address
00549 {
00550 private:
00551         // The validator given to an IPV4Address object must not be a
00552         // transient object, but that must exist at least until the
00553         // last address object of its kind is deleted. This is an
00554         // artifact to be able to do specific checks for derived
00555         // classes inside constructors.
00556         const IPV6Validator *validator;
00557 
00558 protected:
00559         struct in6_addr * ipaddr;
00560         size_t addr_count;
00561         mutable char* hostname;  // hostname for ipaddr[0]. Used by getHostname
00562 #if defined(WIN32)
00563         static MutexCounter counter;
00564 #else
00565         static Mutex mutex;
00566 #endif
00567 
00574         bool setIPAddress(const char *host);
00575 
00582         void setAddress(const char *host);
00583 
00584 public:
00592         IPV6Address(const IPV6Validator *validator = NULL);
00593 
00602         IPV6Address(struct in6_addr addr, const IPV6Validator *validator = NULL);
00603 
00614         IPV6Address(const char *address, const IPV6Validator *validator = NULL);
00615 
00619         IPV6Address(const IPV6Address &rhs);
00620 
00624         virtual ~IPV6Address();
00625 
00632         const char *getHostname(void) const;
00633 
00641         bool isInetAddress(void) const;
00642 
00650         struct in6_addr getAddress(void) const;
00651 
00663         struct in6_addr getAddress(size_t i) const;
00664 
00670         size_t getAddressCount() const { return addr_count; }
00671 
00672         IPV6Address &operator=(const char *str);
00673         IPV6Address &operator=(struct in6_addr addr);
00674         IPV6Address &operator=(const IPV6Address &rhs);
00675 
00676         inline bool operator!() const
00677                 {return !isInetAddress();};
00678 
00687         bool operator==(const IPV6Address &a) const;
00688 
00696         bool operator!=(const IPV6Address &a) const;
00697 };      
00698 
00711 class __EXPORT IPV6Mask : public IPV6Address
00712 {
00713 public:
00720         IPV6Mask(const char *mask);
00721 
00732         friend __EXPORT IPV6Host operator&(const IPV6Host &addr, 
00733                                          const IPV6Mask &mask);
00734 };
00735 
00743 class __EXPORT IPV6Host : public IPV6Address
00744 {
00745 public: 
00758         IPV6Host(const char *host = NULL);
00759 
00767         IPV6Host(struct in6_addr addr);
00768 
00773         IPV6Host &operator&=(const IPV6Mask &mask);
00774 
00775         friend class __EXPORT IPV6Mask;
00776         friend __EXPORT IPV6Host operator&(const IPV6Host &addr, const IPV6Mask &mask);
00777 };
00778 
00783 class __EXPORT IPV6Broadcast : public IPV6Address
00784 {
00785 public:
00793         IPV6Broadcast(const char *net = "255.255.255.255");
00794 };
00795 
00805 class __EXPORT IPV6Multicast: public IPV6Address
00806 {
00807 public:
00812         IPV6Multicast();
00813 
00820         IPV6Multicast(const struct in6_addr address);
00821 
00831         IPV6Multicast(const char *address);
00832         
00833 private:
00841         static const IPV6MulticastValidator validator;
00842 };
00843 
00844 extern __EXPORT std::ostream& operator<<(std::ostream &os, const IPV6Address &ia);
00845 
00846 inline struct in6_addr getaddress(const IPV6Address &ia)
00847         {return ia.getAddress();}
00848 
00849 
00850 #endif
00851 
00852 #ifdef  CCXX_NAMESPACES
00853 }
00854 #endif
00855 
00856 #endif
00857 

Generated on Tue Sep 13 02:19:08 2005 for Bayonne by  doxygen 1.4.4