15 IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4)
24 IPAddr::IPAddr(unsigned ip)
33 IPAddr::IPAddr(std::string ip) throw (std::logic_error)
35 std::istringstream iss(ip);
36 for (int i = 0; i < 4; ++i)
38 if (!std::getline(iss, ip, '.'))
39 throw std::logic_error("Dirección IP inválida");
40 atoms[i] = std::atoi(ip.c_str());
44 /// Operador de casteo a unsigned
45 IPAddr::operator unsigned () const
47 return (atoms[0] << 24) + (atoms[1] << 16) + (atoms[2] << 8) + atoms[3];
50 /// Operador de casteo a std::string
51 IPAddr::operator std::string () const
53 std::ostringstream oss;
54 oss << unsigned(atoms[0]) << "." << unsigned(atoms[1]) << "."
55 << unsigned(atoms[2]) << "." << unsigned(atoms[3]);
59 std::ostream& operator<< (std::ostream& os, const IPAddr& ip)
61 return os << std::string(ip);
64 // vim: set et sw=4 sts=4 :