|
IBR-DTNSuite 0.6
|
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 00035 enum Family 00036 { 00037 VADDRESS_UNSPEC = AF_UNSPEC, 00038 VADDRESS_INET = AF_INET, 00039 VADDRESS_INET6 = AF_INET6, 00040 VADDRESS_UNIX = AF_UNIX 00041 }; 00042 00043 vaddress(const std::string &address); 00044 vaddress(const Family &family = VADDRESS_INET); 00045 vaddress(const Family &family, const std::string &address, const bool broadcast = false); 00046 vaddress(const Family &family, const std::string &address, const int iface, const bool broadcast = false); 00047 virtual ~vaddress(); 00048 00049 Family getFamily() const; 00050 const std::string get(bool internal = true) const; 00051 bool isBroadcast() const; 00052 00058 bool isMulticast() const; 00059 00060 bool operator!=(const vaddress &obj) const; 00061 bool operator==(const vaddress &obj) const; 00062 00063 const std::string toString() const; 00064 00065 struct addrinfo* addrinfo(struct addrinfo *hints) const; 00066 struct addrinfo* addrinfo(struct addrinfo *hints, unsigned int port) const; 00067 00068 static const std::string strip_netmask(const std::string &data); 00069 00070 private: 00071 Family _family; 00072 std::string _address; 00073 bool _broadcast; 00074 int _iface; 00075 }; 00076 } 00077 00078 #endif /* VADDRESS_H_ */