BioInt
1.02.00
BioInt: An integrative biological object-oriented application framework and interpreter
|
00001 #ifndef BIOSOCKETADDRESS_H 00002 #define BIOSOCKETADDRESS_H 00003 00004 #include <stdexcept> 00005 #include <iosfwd> 00006 #include <string> 00007 #include <inttypes.h> 00008 00009 #include "BioSocketCommon.h" 00010 00011 class BioSocketAddress { 00012 00013 struct sockaddr *_M_data; 00014 00015 protected: 00017 int _M_size; 00018 00020 BioSocketAddress(struct sockaddr * _d, int _s) throw() : 00021 _M_data(_d), 00022 _M_size(_s) 00023 { } 00024 00025 virtual ~BioSocketAddress() {} 00026 00028 virtual void reset() throw() = 0; 00029 00030 friend class BioSocket; 00031 00033 struct sockaddr * data() { return _M_data; } 00034 00036 const struct sockaddr * data() const { return _M_data; } 00037 00039 int size() const { return _M_size; } 00040 00042 void size(int _size) { _M_size = _size; } 00043 00044 public: 00046 enum family { 00047 af_unspec = AF_UNSPEC, 00048 af_unix = AF_UNIX, 00049 af_inet = AF_INET, 00050 // af_inet6 = AF_INET6, ///< IPv6 00051 af_max = AF_MAX 00052 }; 00053 }; 00054 00055 class BioSocketAddressIn : public BioSocketAddress { 00056 00057 struct sockaddr_in _M_addr; // for IPv4 00058 00059 protected: 00061 virtual void reset() throw(); 00062 00063 public: 00065 enum address { 00066 addr_any = INADDR_ANY, 00067 addr_loopback = INADDR_LOOPBACK, 00068 addr_broadcast = INADDR_BROADCAST, 00069 addr_none = INADDR_NONE 00070 }; 00071 00072 00074 BioSocketAddressIn() throw(); 00075 00077 BioSocketAddressIn(address _addr, uint16_t _port) throw(); 00078 00080 BioSocketAddressIn(uint32_t _addr, uint16_t _port) throw(); 00081 00083 BioSocketAddressIn(const std::string&, uint16_t) throw (std::invalid_argument); 00084 00086 BioSocketAddressIn(const std::string&) throw (std::invalid_argument); 00087 00089 static bool validate_addr(const std::string&) throw(); 00090 00092 static bool validate_addr_port(const std::string&) throw(); 00093 00094 00096 bool resolve(const std::string&) throw(); 00097 00099 bool resolve_port(const std::string&) throw(); 00100 00102 bool resolve_port(const std::string&, uint16_t) throw(); 00103 00105 bool resolve_port(const std::string&, const std::string&) throw(); 00106 00108 uint16_t port() const throw (); 00109 00111 void port(uint16_t _port) throw (); 00112 00114 bool port(const std::string&, const std::string&) throw(); 00115 00117 bool port(const std::string&) throw(); 00118 00120 uint32_t ip() const throw(); 00121 00123 void ip(uint32_t _host) throw(); 00124 00126 bool ip(const std::string&) throw(); 00127 00128 00130 bool ip_port(const std::string&, uint16_t) throw(); 00131 00133 bool ip_port(const std::string&) throw(); 00134 00136 bool ip_port(const std::string&, const std::string&) throw(); 00137 00138 00140 std::string ip_str() const; 00141 00142 friend std::ostream& operator<<(std::ostream&, const BioSocketAddressIn&); 00143 00144 friend std::istream& operator>>(std::istream&, BioSocketAddressIn&); 00145 }; 00146 00148 std::ostream& operator<<(std::ostream&, const BioSocketAddressIn&); 00149 00151 std::istream& operator>>(std::istream&, BioSocketAddressIn&); 00152 00153 #endif