6 IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4)
15 IPAddr::IPAddr(unsigned ip)
24 IPAddr::IPAddr(std::string ip) throw (std::logic_error)
26 std::istringstream iss(ip);
27 for (int i = 0; i < 4; ++i)
29 if (!std::getline(iss, ip, '.'))
30 throw std::logic_error("Dirección IP inválida");
31 atoms[i] = std::atoi(ip.c_str());
35 /// Operador de casteo a unsigned
36 IPAddr::operator unsigned () const
38 return (atoms[0] << 24) + (atoms[1] << 16) + (atoms[2] << 8) + atoms[3];
41 /// Operador de casteo a std::string
42 IPAddr::operator std::string () const
44 std::ostringstream oss;
45 oss << unsigned(atoms[0]) << "." << unsigned(atoms[1]) << "."
46 << unsigned(atoms[2]) << "." << unsigned(atoms[3]);
50 std::ostream& operator<< (std::ostream& os, const IPAddr& ip)
52 return os << std::string(ip);
55 // vim: set et sw=4 sts=4 :