15 IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4)
24 IPAddr::IPAddr(int ip)
33 IPAddr::IPAddr(const char* ip) throw (std::logic_error)
35 std::istringstream iss(ip);
37 for (int i = 0; i < 4; ++i)
39 if (!std::getline(iss, ips, '.'))
40 throw std::logic_error("Dirección IP inválida");
41 atoms[i] = std::atoi(ips.c_str());
46 //IPAddr::IPAddr(const std::string& ip) throw (std::logic_error)
48 // IPAddr(ip.c_str());
51 /// Operador de casteo a unsigned
52 IPAddr::operator unsigned () const
54 return (atoms[0] << 24) + (atoms[1] << 16) + (atoms[2] << 8) + atoms[3];
57 /// Operador de casteo a std::string
58 IPAddr::operator std::string () const
60 std::ostringstream oss;
61 oss << unsigned(atoms[0]) << "." << unsigned(atoms[1]) << "."
62 << unsigned(atoms[2]) << "." << unsigned(atoms[3]);
66 std::ostream& operator<< (std::ostream& os, const IPAddr& ip)
68 return os << std::string(ip);
71 // vim: set et sw=4 sts=4 :