#ifndef host_h #define host_h /* used by inet_addr, not defined on solaris anywhere!? */ #ifndef INADDR_NONE #define INADDR_NONE ((unsigned long) -1) #include #endif #include #include #include #include #include struct host { host(unsigned int a, unsigned int p) { addr = a; port = p; } host(char *hname, char *pname); host() { addr = 0; port = 0; } sockaddr_in sin() { sockaddr_in s; bzero(&s, sizeof(s)); s.sin_family = AF_INET; s.sin_addr.s_addr = addr; s.sin_port = port; return s; }; unsigned int addr; unsigned int port; }; inline bool operator==(const host &a, const host &b) { return (a.addr == b.addr) && (a.port == b.port); } inline bool operator!=(const host &a, const host &b) { return (a.addr != b.addr) || (a.port != b.port); } inline bool operator>(const host &a, const host &b) { return (ntohl(a.addr) > ntohl(b.addr)) || (a.addr == b.addr && ntohs(a.port) > ntohs(b.port)); } inline bool operator<(const host &a, const host &b) { return (ntohl(a.addr) < ntohl(b.addr)) || (a.addr == b.addr && ntohs(a.port) < ntohs(b.port)); } std::ostream & operator<<(std::ostream &os, const host h); std::ostream & operator<<(std::ostream &os, const std::vector v); bool same_hosts(std::vector a, std::vector b); bool in_hosts(host h, std::vector v); std::vector host_union(std::vector a, std::vector b); #endif