From 25985d60c2f5f2dec658a714b6db5170f113de50 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 6 Jan 2017 11:45:08 +0100 Subject: llmnr-query: Only calculate query length if send was successful Also add a comment indicating the repurposing of the pkt struct. Signed-off-by: Tobias Klauser --- llmnr-query.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llmnr-query.c b/llmnr-query.c index 27a2034..cb2a65e 100644 --- a/llmnr-query.c +++ b/llmnr-query.c @@ -257,8 +257,6 @@ int main(int argc, char **argv) } } - query_pkt_len = pkt_len(p) - sizeof(*hdr); - if (sendto(sock, p->data, pkt_len(p), 0, (struct sockaddr *)&sst, sizeof(sst)) < 0) { log_err("Failed to send UDP packet: %s\n", strerror(errno)); break; @@ -278,7 +276,10 @@ int main(int argc, char **argv) } else if (ret) { uint16_t j, ancount; + /* save query length and re-use packet for RX */ + query_pkt_len = pkt_len(p) - sizeof(*hdr); pkt_reset(p); + if (recv(sock, p->data, p->size, 0) < 0) { log_err("Failed to receive from socket: %s\n", strerror(errno)); break; -- cgit v1.2.3-54-g00ecf