--- gvpe/src/sockinfo.h 2005/03/18 01:53:05 1.11 +++ gvpe/src/sockinfo.h 2007/12/02 00:09:36 1.14 @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with gvpe; if not, write to the Free Software - Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GVPE_SOCKINFO_H__ @@ -29,44 +29,49 @@ // encapsulate one or more network addresses. this structure // gets transferred over the wire, so be careful with endianness etc. struct sockinfo +{ + u32 host; + u16 port; + u8 prot; + u8 pad1; + + void set (const sockaddr_in *sa, u8 prot_); + void set (const conf_node *conf, u8 prot_); + void set (const char *hostname, u16 port_, u8 prot_); + + // return the supported protocols + u8 supported_protocols (conf_node *conf = 0); + bool upgrade_protocol (u8 prot_, conf_node *conf = 0); + + operator const char *() const; + + const sockaddr *sav4 () const; + const socklen_t salenv4 () const + { + return sizeof (sockaddr_in); + } + + const char *ntoa () const; + + bool valid () const { - u32 host; - u16 port; - u8 prot; - u8 pad1; - - void set (const sockaddr_in *sa, u8 prot_); - void set (const conf_node *conf, u8 prot_); - void set (const char *hostname, u16 port_, u8 prot_); - - // return the supported protocols - u8 supported_protocols (conf_node *conf = 0); - bool upgrade_protocol (u8 prot_, conf_node *conf = 0); - - operator const char *() const; - - const sockaddr *sav4 () const; - const socklen_t salenv4 () const - { - return sizeof (sockaddr_in); - } - - const char *ntoa () const; - - bool valid () const - { - return prot != 0 && host != 0; - } - - sockinfo() { prot = 0; } - - sockinfo(const char *hostname, u16 port, u8 prot) { set (hostname, port, prot); } - sockinfo(const sockaddr_in &sa, u8 prot) { set (&sa, prot); } - sockinfo(const conf_node *conf, u8 prot) { set (conf, prot); } - }; + return prot != 0 && host != 0; + } + + sockinfo() { prot = 0; } + + sockinfo(const char *hostname, u16 port, u8 prot) { set (hostname, port, prot); } + sockinfo(const sockaddr_in &sa, u8 prot) { set (&sa, prot); } + sockinfo(const conf_node *conf, u8 prot) { set (conf, prot); } +}; bool operator == (const sockinfo &a, const sockinfo &b); -bool operator < (const sockinfo &a, const sockinfo &b); +bool operator < (const sockinfo &a, const sockinfo &b); + +inline bool operator != (const sockinfo &a, const sockinfo &b) +{ + return !(a == b); +} #endif