15 IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4)
24 IPAddr::IPAddr(uint32_t ip)
34 IPAddr::IPAddr(const char* ip) throw (std::logic_error)
36 std::istringstream iss(ip);
38 for (int i = 0; i < 4; ++i)
40 if (!std::getline(iss, ips, '.'))
41 throw std::logic_error("Dirección IP inválida");
42 atoms[i] = std::atoi(ips.c_str());
48 IPAddr::IPAddr(const std::string& ip) throw (std::logic_error)
50 std::istringstream iss(ip);
52 for (int i = 0; i < 4; ++i)
54 if (!std::getline(iss, ips, '.'))
55 throw std::logic_error("Dirección IP inválida");
56 atoms[i] = std::atoi(ips.c_str());
60 /// Operador de casteo a unsigned
61 IPAddr::operator uint32_t () const
63 return (atoms[0] << 24) + (atoms[1] << 16) + (atoms[2] << 8) + atoms[3];
66 /// Operador de casteo a std::string
67 IPAddr::operator std::string () const
69 std::ostringstream oss;
70 oss << unsigned(atoms[0]) << "." << unsigned(atoms[1]) << "."
71 << unsigned(atoms[2]) << "." << unsigned(atoms[3]);
75 std::ostream& operator<< (std::ostream& os, const IPAddr& ip)
77 return os << std::string(ip);
80 // vim: set et sw=4 sts=4 :