00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __UTIL_H
00034 #define __UTIL_H
00035
00036
00037
00038 #include <errno.h>
00039 #include <string>
00040
00041 #include "MaceTypes.h"
00042 #include "Exception.h"
00043
00044
00045
00064 class Util {
00065 public:
00066 static const uint16_t DEFAULT_MACE_PORT = 5377;
00067 static const bool REPLAY;
00068
00069 public:
00070 static const MaceAddr& getMaceAddr() throw (AddressException);
00071 static int getAddr() throw (AddressException);
00072
00073
00074 static int getAddr(const std::string& hostname) throw (AddressException);
00075 static uint16_t getPort();
00076 static int getHostByName(const std::string& hostname) throw (AddressException);
00077 static MaceAddr getMaceAddr(const std::string& hostname) throw (AddressException);
00078 static std::string getHostname();
00079
00085 static bool isPrivateAddr(uint32_t a);
00086 static bool isHostReachable(const MaceKey& k);
00087
00088
00092 static std::string getHostname(const MaceKey& k) throw (AddressException);
00093 static std::string getHostname(const std::string& ipaddr) throw (AddressException);
00094 static std::string getHostname(int ipaddr);
00095 static std::string getHostByAddr(int ipaddr);
00096 static std::string getAddrString(int ipaddr);
00097 static std::string getAddrString(const std::string& hostname) throw (AddressException);
00098
00106 static std::string getAddrString(const MaceAddr& addr, bool resolve = true);
00107
00115 static std::string getAddrString(const SockAddr& addr, bool resolve = true);
00116
00124 static void printAddrString(std::ostream& out, const MaceAddr& addr, bool resolve = true);
00125
00133 static void printAddrString(std::ostream& out, const SockAddr& addr, bool resolve = true);
00134
00142 static void printAddrString(std::ostream& out, const std::string& hostname) throw (AddressException);
00143
00151 static void printAddrString(std::ostream& out, int ipaddr);
00152
00153 static std::string getErrorString(int err);
00154 static std::string getSslErrorString();
00155
00156 static mace::map<int, int> makeMap(int first ...);
00157
00158 static void nodeSetDiff(const NodeSet& prev, const NodeSet& cur,
00159 NodeSet& added, NodeSet& removed);
00160
00161 private:
00162 static const size_t DNS_CACHE_TIMEOUT = 10 * 60;
00163 static const unsigned DNS_CACHE_SIZE = 64;
00164 static uint16_t baseport;
00165 };
00166
00169 #endif // __UTIL_H