24 #include <sys/socket.h> 26 #include <boost/lexical_cast.hpp> 27 #include <boost/regex.hpp> 41 std::string::size_type portIx = addr.find(
':');
43 port( boost::lexical_cast< ::uint16_t>(portIx == std::string::npos ? addr : std::string(addr,portIx+1)) );
45 catch (boost::bad_lexical_cast
const &) {
48 if (portIx != std::string::npos)
80 is.setstate(std::ios::failbit);
96 static boost::regex
const addressRx (
"(?:(?:\\[([^%]+)(?:%(.+))?\\]|(.+)):)?([0-9]+)");
104 if (! regex_match(addr, match, addressRx))
107 if (match[ZoneId].matched)
108 assignIface(match[ZoneId]);
110 sockaddr_.sin6_port = htons(boost::lexical_cast<boost::uint16_t>(match[Port]));
112 if (match[Address].matched || match[Hostname].matched) {
114 match[Address].matched ? match[Address] : match[Hostname],
116 std::copy(a.begin(), a.end(), &sockaddr_.sin6_addr.s6_addr[0]);
123 if (sockaddr_.sin6_scope_id == 0)
125 char buffer[IFNAMSIZ];
127 "Internal failure: Invalid interface index (how does it get here?)");
128 return std::string(buffer);
131 prefix_ void senf::INet6SocketAddress::assignIface(std::string
const &
iface)
134 sockaddr_.sin6_scope_id = 0;
136 sockaddr_.sin6_scope_id = if_nametoindex(iface.c_str());
137 if (sockaddr_.sin6_scope_id == 0)
148 os <<
"]:" << addr.
port();
161 is.setstate(std::ios::failbit);
static INet6Address from_string(std::string const &s, Resolve_t resolve=ResolveINet6)
Convert string to address.
#define SENF_ASSERT_EXPRESSION(expression, comment)
std::ostream & operator<<(std::ostream &os, Packet const &packet)
std::istream & operator>>(std::istream &is, INet4SocketAddress &addr)
std::string iface() const
Get interface name.
AddressExceptions public header.
unsigned port() const
Get port number.
static INet4Address from_string(std::string const &s)
Convert string to address.
Socket addressing, BSD style.
INet[46]Address and INet[46]AddressingPolicy public header.
Base-class for Address exceptions.
INet6Address address() const
Get printable address representation.
unsigned port() const
Return port number.
INet4Address address() const
Return address.
INet6SocketAddress()
Create empty instance.