mirror of https://github.com/Chizi123/dnscomp.git

Joel Grunbaum
2020-10-19 bb2e576b97f841a4e5aa8671a86ac34f960cbd7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "dns.h"
 
int main(int argc, char** argv)
{
     int option, type = T_A;
     char* server = "1.1.1.1", *hostname = "google.com";
     while((option = getopt(argc, argv, "s:h:t:")) != -1) {
          switch (option) {
          case 's': //server to use
               server = optarg;
               break;
          case 'h': //hostname to search
               hostname = optarg;
               break;
          case 't':
               if (!strcmp(optarg, "A")) {
                    type = T_A;
               } else if (!strcmp(optarg, "AAAA")) {
                    type = T_AAAA;
               } else if (!strcmp(optarg, "NS")) {
                    type = T_NS;
               } else if (!strcmp(optarg, "CNAME")) {
                    type = T_CNAME;
               } else if (!strcmp(optarg, "SOA")) {
                    type = T_SOA;
               } else if (!strcmp(optarg, "PTR")) {
                    type = T_PTR;
               } else if (!strcmp(optarg, "MX")) {
                    type = T_MX;
               } else if (!strcmp(optarg, "TXT")) {
                    type = T_MX;
               } else {
                    printf("Error: %s is not a valid DNS record type\n", optarg);
                    exit(1);
               }
               break;
          case '?':
          default:
               printf("Error: invalid option -%c\n", optopt);
               exit(1);
          }
     }
     unsigned char buf[65536];
     struct timespec time;
     time = resolve(buf, hostname, server, type);
     printf("Request took %ld.%09lds\n", time.tv_sec, time.tv_nsec);
     print_packet(buf);
     return 0;
}