21 #include <arpa/inet.h> 23 #include <sys/socket.h> 24 #include <boost/lexical_cast.hpp> 25 #if defined(_REENTRANT) && !defined(__GLIBC__) 26 #include <boost/thread/mutex.hpp> 38 iref() = htonl(value);
44 if (::inet_pton(AF_INET,s.c_str(),&ina) > 0)
55 struct hostent entbuf;
57 struct hostent * ent (0);
59 ::gethostbyname2_r(s.c_str(), AF_INET, &entbuf, buffer,
sizeof(buffer), &ent, &herr);
64 static boost::mutex mutex;
65 boost::mutex::scoped_lock lock(mutex);
67 struct hostent * ent (::gethostbyname(s.c_str()));
72 if (ent->h_addrtype != AF_INET)
77 reinterpret_cast<in_addr*>(*(ent->h_addr_list))->s_addr);
85 (l & 0xFF000000u) == 0x0A000000u ||
86 (l & 0xFFF00000u) == 0xAC100000u ||
87 (l & 0xFFFF0000u) == 0xA9FE0000u ||
88 (l & 0xFFFF0000u) == 0xC0A80000u;
94 return (
address() & 0xFF000000u) == 0x7F000000u;
100 return (
address() & 0xF0000000u) == 0xE0000000u;
106 return ntohl(iref());
118 std::string::size_type i (s.find(
'/'));
119 if (i == std::string::npos)
122 prefix_len_ = prefix_len_checked(boost::lexical_cast<unsigned>(std::string(s,i+1)));
123 }
catch (boost::bad_lexical_cast
const &) {
136 ina.s_addr = addr.
inaddr();
137 ::inet_ntop(AF_INET,&ina,buffer,16);
152 is.setstate(std::ios::failbit);
166 is.setstate(std::ios::failbit);
static INet4Address const Broadcast
address_type address() const
Return address represented as integer number.
bool local() const
true, if address is locally administered
std::ostream & operator<<(std::ostream &os, Packet const &packet)
std::istream & operator>>(std::istream &is, INet4SocketAddress &addr)
static INet4Address const None
The empty (0) address.
INet4Address public header.
static INet4Address from_inaddr(inaddr_type v)
Construct address from integer in network byte order.
bool multicast() const
true, if address is a multicast address
static INet4Address from_string(std::string const &s)
Convert string to address.
bool loopback() const
true, if address is within the loopback network
uint32_t address_type
Address representation as number in host byte order.
inaddr_type inaddr() const
Return the raw network byte order address.
static INet4Address const Loopback
The loopback (127.0.0.1) address.
Base-class for Address exceptions.
INet4Address()
Construct an empty address.
INet4Network()
Construct empty (0.0.0.0/0) network.