00001 /* -*- mode: c++; c-basic-offset: 4; -*- */ 00002 #ifndef LMSG_MSGADDR_HH 00003 #define LMSG_MSGADDR_HH 00004 00005 #include <string> 00006 #include <iosfwd> 00007 00008 #ifndef __CINT__ 00009 struct sockaddr_in; 00010 #else 00011 struct sockaddr_in { 00012 short sin_family; 00013 short sin_port; 00014 unsigned int sin_addr; 00015 char sin_zero[8]; 00016 }; 00017 #endif 00018 00019 namespace lmsg { 00020 00033 class MsgAddr { 00034 public: 00037 typedef unsigned int ipaddr_t; 00038 00041 typedef unsigned short ipport_t; 00042 00045 typedef ::sockaddr_in ipsock_t; 00046 public: 00047 00050 ~MsgAddr(void); 00051 00056 MsgAddr(void); 00057 00063 MsgAddr(const ipsock_t& sock); 00064 00070 MsgAddr(const MsgAddr& addr); 00071 00080 MsgAddr(ipaddr_t node, ipport_t port=0, ipport_t subp=0); 00081 00087 MsgAddr& operator=(const MsgAddr& addr); 00088 00095 bool operator==(const MsgAddr& s) const; 00096 00103 bool operator!=(const MsgAddr& s) const; 00104 00109 ipaddr_t getIPAddr(void) const; 00110 00115 ipport_t getIPPort(void) const; 00116 00121 ipport_t getSubProcess(void) const; 00122 00127 void getAddr(ipsock_t& sock) const; 00128 00133 void setIPAddr(ipaddr_t sock); 00134 00139 void setIPPort(ipport_t port); 00140 00145 void setSubProcess(ipport_t proc); 00146 00151 void setAddr(const ipsock_t& sock); 00152 00160 static MsgAddr findIPHost(const std::string& hostName); 00161 00166 std::string getIPName(void) const; 00167 00168 private: 00169 ipaddr_t ip_addr; 00170 ipport_t ip_port; 00171 ipport_t subprocess; 00172 }; 00173 00174 } // namespace lmsg 00175 00176 //-------------------------------------- Non Member method 00181 std::ostream& 00182 operator<<(std::ostream& out, const lmsg::MsgAddr& addr); 00183 00184 //-------------------------------------- Inline methods 00185 #ifndef __CINT__ 00186 inline bool 00187 lmsg::MsgAddr::operator==(const MsgAddr& s) const { 00188 return (ip_addr == s.ip_addr) && 00189 (ip_port == s.ip_port) && 00190 (subprocess == s.subprocess); 00191 } 00192 00193 inline bool 00194 lmsg::MsgAddr::operator!=(const MsgAddr& s) const { 00195 return !operator==(s); 00196 } 00197 #endif // !def(__CINT__) 00198 00199 #endif // LMSG_MSGADDR_HH 00200
1.5.4