X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/037c7a6a269f053f09e3ebab3c28e4453b576d18..c1b28b595a388df043997c87faf75c06959405d0:/practicas/pipi/src/resolvproto.cpp?ds=inline diff --git a/practicas/pipi/src/resolvproto.cpp b/practicas/pipi/src/resolvproto.cpp index 92a5512..fe2f94a 100644 --- a/practicas/pipi/src/resolvproto.cpp +++ b/practicas/pipi/src/resolvproto.cpp @@ -89,14 +89,14 @@ void ResolvProtoResponse::recv(int sockfd) if (libtcp_receive_bin(sockfd, &ret, sizeof(uint8_t)) != sizeof(uint8_t)) throw std::runtime_error("Error al recibir ret por socket"); uint8_t count; - if (libtcp_send(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t)) + if (libtcp_receive_bin(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t)) throw std::runtime_error("Error al recibir count por socket"); ips.clear(); ips.reserve(count); for (uint8_t i = 0; i < count; ++i) { uint32_t ip; - if (libtcp_send(sockfd, &ip, sizeof(uint32_t)) != sizeof(uint32_t)) + if (libtcp_receive_bin(sockfd, &ip, sizeof(uint32_t)) != sizeof(uint32_t)) throw std::runtime_error("Error al recibir IPAddr por socket"); ips.push_back(ip); } @@ -105,10 +105,12 @@ void ResolvProtoResponse::recv(int sockfd) /// Impresión de response std::ostream& operator<< (std::ostream& os, const ResolvProtoResponse& rpr) { + if (rpr.ips.empty()) + return os; os << "ResolvProtoResponse(ret=" << unsigned(rpr.ret) << ", "; - std::copy(rpr.ips.begin(), rpr.ips.end(), + std::copy(rpr.ips.begin(), rpr.ips.end() - 1, std::ostream_iterator< IPAddr >(os, ", ")); - return os << ")"; + return os << rpr.ips.back() << ")"; } // vim: set et sw=4 sts=4 :