prefix_ senf::INet4SocketAddress::INet4SocketAddress(std::string const & addr)
: BSDSocketAddress (sizeof(sockaddr_in), AF_INET)
{
- unsigned portIx = addr.find(':');
+ std::string::size_type portIx = addr.find(':');
try {
- port( boost::lexical_cast< ::u_int16_t >(portIx == std::string::npos
+ port( boost::lexical_cast< ::u_int16_t >(portIx == std::string::npos
? addr : std::string(addr,portIx+1)) );
}
catch (boost::bad_lexical_cast const &) {
port(p);
}
+prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4SocketAddress const & addr)
+{
+ os << addr.address() << ":" << addr.port();
+ return os;
+}
+
+prefix_ std::istream & senf::operator>>(std::istream & is, INet4SocketAddress & addr)
+{
+ std::string s;
+ if (!(is >> s))
+ return is;
+ try {
+ addr = INet4SocketAddress(s);
+ }
+ catch (AddressException &) {
+ is.setstate(std::ios::failbit);
+ }
+ return is;
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::INet6SocketAddress
ZoneId = 2,
Hostname = 3,
Port = 4 };
-
+
boost::smatch match;
if (! regex_match(addr, match, addressRx))
throw AddressSyntaxException();
}
}
+prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6SocketAddress const & addr)
+{
+ os << '[' << addr.address();
+ std::string iface (addr.iface());
+ if (! iface.empty())
+ os << '%' << iface;
+ os << "]:" << addr.port();
+ return os;
+}
+
+prefix_ std::istream & senf::operator>>(std::istream & is, INet6SocketAddress & addr)
+{
+ std::string s;
+ if (!(is >> s))
+ return is;
+ try {
+ addr = INet6SocketAddress(s);
+ }
+ catch (AddressException &) {
+ is.setstate(std::ios::failbit);
+ }
+ return is;
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "INetAddressing.mpp"
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100