X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/77a15cf8943d5588e17815771420d189f3f8bca8..0a2739fe97762f57a80599ef170df98e07422a3d:/practicas/pipi/src/ipaddr.cpp?ds=sidebyside diff --git a/practicas/pipi/src/ipaddr.cpp b/practicas/pipi/src/ipaddr.cpp index 5f33669..1cdd573 100644 --- a/practicas/pipi/src/ipaddr.cpp +++ b/practicas/pipi/src/ipaddr.cpp @@ -2,6 +2,15 @@ #include "ipaddr.h" #include +/// Constructor +IPAddr::IPAddr() +{ + atoms[0] = 0; + atoms[1] = 0; + atoms[2] = 0; + atoms[3] = 0; +} + /// Constructor IPAddr::IPAddr(atom a1, atom a2, atom a3, atom a4) { @@ -12,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; @@ -21,14 +30,15 @@ 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()); } }