00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SOCK_ADDR_H
00023 #define SOCK_ADDR_H
00024
00025
00031 #include <stdexcept>
00032 #include <iosfwd>
00033 #include <string>
00034 #include <inttypes.h>
00035
00036
00037 #include "sockcommon.h"
00038
00039 namespace socklibpp {
00040
00042 class addr {
00043
00044 struct sockaddr *_M_data;
00045
00046 protected:
00048 int _M_size;
00049
00051 addr(struct sockaddr * _d, int _s) throw() :
00052 _M_data(_d),
00053 _M_size(_s)
00054 { }
00055
00056 virtual
00057 ~addr() {}
00058
00060 virtual void reset() throw() = 0;
00061
00062 friend class sock;
00063
00065 struct sockaddr *
00066 data() { return _M_data; }
00067
00069 const struct sockaddr *
00070 data() const { return _M_data; }
00071
00073 int
00074 size() const { return _M_size; }
00075
00077 void
00078 size(int _size) { _M_size = _size; }
00079
00080 public:
00081
00083 enum family {
00084 af_unspec = AF_UNSPEC,
00085 af_unix = AF_UNIX,
00086 af_inet = AF_INET,
00087 af_inet6 = AF_INET6,
00088 af_max = AF_MAX
00089 };
00090 };
00091
00092
00093
00098 class addr_in : public addr {
00099
00100 struct sockaddr_in _M_addr;
00101
00102 protected:
00104 virtual void reset() throw();
00105
00106 public:
00108 enum address {
00109 addr_any = INADDR_ANY,
00110 addr_loopback = INADDR_LOOPBACK,
00111 addr_broadcast = INADDR_BROADCAST,
00112 addr_none = INADDR_NONE
00113 };
00114
00115
00117 addr_in() throw();
00118
00120 addr_in(address _addr, uint16_t _port) throw();
00121
00123 addr_in(uint32_t _addr, uint16_t _port) throw();
00124
00126 addr_in(const std::string&, uint16_t) throw (std::invalid_argument);
00127
00129 addr_in(const std::string&) throw (std::invalid_argument);
00130
00132 static bool validate_addr(const std::string&) throw();
00133
00135 static bool validate_addr_port(const std::string&) throw();
00136
00137
00139 bool
00140 resolve(const std::string&) throw();
00141
00143 bool
00144 resolve_port(const std::string&) throw();
00145
00147 bool
00148 resolve_port(const std::string&, uint16_t) throw();
00149
00151 bool
00152 resolve_port(const std::string&, const std::string&) throw();
00153
00155 uint16_t port() const throw ();
00156
00158 void port(uint16_t _port) throw ();
00159
00161 bool port(const std::string&, const std::string&) throw();
00162
00164 bool port(const std::string&) throw();
00165
00167 uint32_t ip() const throw();
00168
00170 void ip(uint32_t _host) throw();
00171
00173 bool
00174 ip(const std::string&) throw();
00175
00176
00178 bool
00179 ip_port(const std::string&, uint16_t) throw();
00180
00182 bool
00183 ip_port(const std::string&) throw();
00184
00186 bool
00187 ip_port(const std::string&, const std::string&) throw();
00188
00189
00191 std::string ip_str() const;
00192
00193
00194
00195
00196
00197 friend
00198 std::ostream& operator<<(std::ostream&, const addr_in&);
00199
00200 friend
00201 std::istream& operator>>(std::istream&, addr_in&);
00202 };
00203
00205 std::ostream& operator<<(std::ostream&, const addr_in&);
00206
00208 std::istream& operator>>(std::istream&, addr_in&);
00209
00210 }
00211
00212
00213 #endif