From 803d663003366f0899ffa274142c824a9f53d44d Mon Sep 17 00:00:00 2001 From: Joel Grunbaum <joelgrun@gmail.com> Date: Sun, 18 Oct 2020 01:56:10 +0000 Subject: [PATCH] dns records fetched and printing --- main.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 7836ad1..3c5961c 100644 --- a/main.c +++ b/main.c @@ -143,8 +143,8 @@ answers[i].resource = (struct R_DATA*)reader; reader = reader+sizeof(struct R_DATA); - if (ntohs(answers[i].resource->type) == 1) { //IPv6 address - answers[i].rdata[j] = (unsigned char*)malloc(ntohs(answers[i].resource->data_len)); + if (ntohs(answers[i].resource->type) == T_A) { //IPv4 address + answers[i].rdata = (unsigned char*)malloc(ntohs(answers[i].resource->data_len)); for (j = 0; j < ntohs(answers[i].resource->data_len); j++) { answers[i].rdata[j] = reader[j]; } @@ -190,7 +190,7 @@ printf("ans recs: %d\n", ntohs(dns->ans_count)); for (i = 0; i < ntohs(dns->ans_count); i++) { printf("name: %s ", answers[i].name); - if (ntohs(answers[i].resource->type == T_A)) { //IPv4 + if (ntohs(answers[i].resource->type) == T_A) { //IPv4 long* p; p = (long*)answers[i].rdata; a.sin_addr.s_addr=(*p); @@ -221,13 +221,15 @@ void change_to_DNS_name_format(unsigned char* dns, unsigned char* host) { int lock = 0; - strcat((char*)host,"."); + char h[300]; + strcpy(h, host); + strcat((char*)h,"."); - for (int i = 0; i < strlen((char*)host); i++) { - if (host[i] == '.') { + for (int i = 0; i < strlen((char*)h); i++) { + if (h[i] == '.') { *dns++ = i-lock; - for (;lock<i;i++) { - *dns++ = host[lock]; + for (;lock<i;lock++) { + *dns++ = h[lock]; } lock++; } @@ -258,7 +260,7 @@ } } name[p] = '\0'; - if (jumped == 0) { + if (jumped == 1) { *count = *count + 1; } -- Gitblit v1.10.0