}
/// Constructor
-ResolvProtoRequest::ResolvProtoRequest(std::string name, uint8_t type):
- type(type), name(name)
+ResolvProtoRequest::ResolvProtoRequest(std::string name, uint8_t query_type):
+ query_type(query_type), name(name)
{}
/// Envía por socket
void ResolvProtoRequest::send(int sockfd) const
throw (std::runtime_error)
{
- if (libtcp_send(sockfd, &type, sizeof(uint8_t)) != sizeof(uint8_t))
- throw std::runtime_error("Error al enviar type por socket");
+ if (libtcp_send(sockfd, &query_type, sizeof(uint8_t)) != sizeof(uint8_t))
+ throw std::runtime_error("Error al enviar query_type por socket");
uint16_t size = name.size();
if (libtcp_send(sockfd, &size, sizeof(uint16_t)) != sizeof(uint16_t))
throw std::runtime_error("Error al enviar size por socket");
void ResolvProtoRequest::recv(int sockfd)
throw (std::runtime_error)
{
- if (libtcp_receive_bin(sockfd, &type, sizeof(uint8_t)) != sizeof(uint8_t))
- throw std::runtime_error("Error al recibir type por socket");
+ if (libtcp_receive_bin(sockfd, &query_type, sizeof(uint8_t)) != sizeof(uint8_t))
+ throw std::runtime_error("Error al recibir query_type por socket");
uint16_t size;
if (libtcp_receive_bin(sockfd, &size, sizeof(uint16_t)) != sizeof(uint16_t))
throw std::runtime_error("Error al recibir size por socket");
/// Impresión de request
std::ostream& operator<< (std::ostream& os, const ResolvProtoRequest& rpr)
{
- return os << "ResolvProtoRequest(type=" << unsigned(rpr.type) << ", name="
- << rpr.name << ")";
+ return os << "ResolvProtoRequest(query_type=" << unsigned(rpr.query_type)
+ << ", name=" << rpr.name << ")";
+}
+
+/// Constructor
+ResolvProtoResponse::ResolvProtoResponse(): ret(R_NOTFOUND), ttl(0)
+{
}
/// Constructor
}
/// Constructor
-ResolvProtoResponse::ResolvProtoResponse(ret_t ret):
- ret(ret)
+ResolvProtoResponse::ResolvProtoResponse(ret_t ret, uint32_t ttl,
+ const ipvec_t& ips):
+ ret(ret), ttl(ttl), ips(ips)
{}
/// Envía por socket
{
if (libtcp_send(sockfd, &ret, sizeof(uint8_t)) != sizeof(uint8_t))
throw std::runtime_error("Error al enviar ret por socket");
+ if (libtcp_send(sockfd, &ttl, sizeof(uint32_t)) != sizeof(uint32_t))
+ throw std::runtime_error("Error al enviar ttl por socket");
uint8_t count = ips.size();
if (libtcp_send(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t))
throw std::runtime_error("Error al enviar count por socket");
{
if (libtcp_receive_bin(sockfd, &ret, sizeof(uint8_t)) != sizeof(uint8_t))
throw std::runtime_error("Error al recibir ret por socket");
+ if (libtcp_receive_bin(sockfd, &ttl, sizeof(uint32_t)) != sizeof(uint32_t))
+ throw std::runtime_error("Error al recibir ttl por socket");
uint8_t count;
if (libtcp_receive_bin(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t))
throw std::runtime_error("Error al recibir count por socket");
/// Impresión de response
std::ostream& operator<< (std::ostream& os, const ResolvProtoResponse& rpr)
{
+ os << "ResolvProtoResponse(ret=" << unsigned(rpr.ret)
+ << ", ttl=" << rpr.ttl;
if (rpr.ips.empty())
- return os;
- os << "ResolvProtoResponse(ret=" << unsigned(rpr.ret) << ", ";
+ return os << ")";
+ os << ", ";
std::copy(rpr.ips.begin(), rpr.ips.end() - 1,
std::ostream_iterator< IPAddr >(os, ", "));
return os << rpr.ips.back() << ")";