X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/7a01801db38786c0f1cab79b3867b8b529d5cb1c..55584999e396fae97c47a9d83d35d6b45c7bed97:/practicas/pipi/src/ipaddr.cpp?ds=sidebyside diff --git a/practicas/pipi/src/ipaddr.cpp b/practicas/pipi/src/ipaddr.cpp index 6b052c8..7b153b2 100644 --- a/practicas/pipi/src/ipaddr.cpp +++ b/practicas/pipi/src/ipaddr.cpp @@ -21,7 +21,7 @@ IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4) } /// Constructor -IPAddr::IPAddr(unsigned ip) +IPAddr::IPAddr(int ip) { atoms[0] = ip >> 24; atoms[1] = ip >> 16; @@ -30,17 +30,24 @@ IPAddr::IPAddr(unsigned ip) } /// Constructor -IPAddr::IPAddr(std::string ip) throw (std::logic_error) +IPAddr::IPAddr(const char* ip) throw (std::logic_error) { std::istringstream iss(ip); + std::string ips; for (int i = 0; i < 4; ++i) { - if (!std::getline(iss, ip, '.')) + if (!std::getline(iss, ips, '.')) throw std::logic_error("Dirección IP inválida"); - atoms[i] = std::atoi(ip.c_str()); + atoms[i] = std::atoi(ips.c_str()); } } +/// Constructor +//IPAddr::IPAddr(const std::string& ip) throw (std::logic_error) +//{ +// IPAddr(ip.c_str()); +//} + /// Operador de casteo a unsigned IPAddr::operator unsigned () const {