IBR-DTNSuite  0.8
ibrcommon/ibrcommon/net/vaddress.h
Go to the documentation of this file.
00001 /*
00002  * vaddress.h
00003  *
00004  *  Created on: 14.12.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef VADDRESS_H_
00009 #define VADDRESS_H_
00010 
00011 #include "ibrcommon/Exceptions.h"
00012 #include <sys/socket.h>
00013 #include <netdb.h>
00014 
00015 namespace ibrcommon
00016 {
00017         class vaddress
00018         {
00019                 public:
00020                         class address_not_set : public Exception
00021                         {
00022                         public:
00023                                 address_not_set(string error = "address is not specified") : Exception(error)
00024                                 {};
00025                         };
00026 
00027                         class family_not_set : public Exception
00028                         {
00029                         public:
00030                                 family_not_set(string error = "family is not specified") : Exception(error)
00031                                 {};
00032                         };
00033 
00034                         enum Family
00035                         {
00036                                 VADDRESS_UNSPEC = AF_UNSPEC,
00037                                 VADDRESS_INET = AF_INET,
00038                                 VADDRESS_INET6 = AF_INET6,
00039                                 VADDRESS_UNIX = AF_UNIX
00040                         };
00041 
00042                         vaddress(const std::string &address);
00043                         vaddress(const Family &family = VADDRESS_INET);
00044                         vaddress(const Family &family, const std::string &address, const bool broadcast = false);
00045                         vaddress(const Family &family, const std::string &address, const int iface, const bool broadcast = false);
00046                         virtual ~vaddress();
00047 
00048                         Family getFamily() const;
00049                         const std::string get(bool internal = true) const;
00050                         bool isBroadcast() const;
00051 
00057                         bool isMulticast() const;
00058 
00059                         bool operator!=(const vaddress &obj) const;
00060                         bool operator==(const vaddress &obj) const;
00061 
00062                         const std::string toString() const;
00063 
00064                         struct addrinfo* addrinfo(struct addrinfo *hints) const;
00065                         struct addrinfo* addrinfo(struct addrinfo *hints, unsigned int port) const;
00066 
00067                         static const std::string strip_netmask(const std::string &data);
00068 
00069                 private:
00070                         static const std::string __REGEX_IPV6_ADDRESS__;
00071                         static const std::string __REGEX_IPV4_ADDRESS__;
00072 
00073                         Family _family;
00074                         std::string _address;
00075                         bool _broadcast;
00076                         int _iface;
00077         };
00078 }
00079 
00080 #endif /* VADDRESS_H_ */