// $Id$
//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
#include <netdb.h>
#include <sys/socket.h>
#include <boost/lexical_cast.hpp>
-#ifdef _REENTRANT
+#if defined(_REENTRANT) && !defined(__GLIBC__)
#include <boost/thread/mutex.hpp>
#endif
return senf::INet4Address::from_inaddr(ina.s_addr);
if (s.empty())
- throw SyntaxException();
+ throw AddressSyntaxException();
int herr (0);
// If available, we use the reentrant GNU variant. This has the additional advantage, that we
- // can explicitly ask for IpV4 addresses
+ // can explicitly ask for IPv4 addresses
# ifdef __GLIBC__
# endif // __GLIBC__
if (!ent)
- throw UnknownHostnameException();
+ throw UnknownHostnameException(s);
if (ent->h_addrtype != AF_INET)
- throw UnknownHostnameException();
+ throw UnknownHostnameException(s);
// We are only interested in the first address ...
return senf::INet4Address::from_inaddr(
const
{
address_type l (address());
- return
+ return
(l & 0xFF000000u) == 0x0A000000u ||
(l & 0xFFF00000u) == 0xAC100000u ||
(l & 0xFFFF0000u) == 0xA9FE0000u ||
///////////////////////////////////////////////////////////////////////////
// senf::INet4Network
-prefix_ senf::INet4Network::INet4Network(std::string s)
+prefix_ senf::INet4Network::INet4Network(std::string const & s)
{
std::string::size_type i (s.find('/'));
if (i == std::string::npos)
- throw INet4Address::SyntaxException();
+ throw AddressSyntaxException();
try {
prefix_len_ = boost::lexical_cast<unsigned>(std::string(s,i+1));
} catch (boost::bad_lexical_cast const &) {
- throw INet4Address::SyntaxException();
+ throw AddressSyntaxException();
}
address_ = INet4Address(INet4Address::from_string(std::string(s, 0, i)).address() & mask());
}
char buffer[16];
ina.s_addr = addr.inaddr();
::inet_ntop(AF_INET,&ina,buffer,16);
- buffer[15] = 0;
+ buffer[15] = 0;
os << buffer;
return os;
}
+prefix_ std::istream & senf::operator>>(std::istream & is, INet4Address & addr)
+{
+ std::string s;
+ if (!(is >> s))
+ return is;
+ try {
+ addr = INet4Address::from_string(s);
+ }
+ catch (AddressException &) {
+ is.setstate(std::ios::failbit);
+ }
+ return is;
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "INet4Address.mpp"
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100