-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.c
84 lines (74 loc) · 2.03 KB
/
client.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "socket_utils.h"
#include "constructor.h"
#include "parser.h"
#include "dns_c.h"
int _hex_print( unsigned char* array, int size);
int remove_www(char *url);
int main( int argc, char **argv ){
struct DNS_REQUEST question;
unsigned char answer[SIZE_OF_RESP];
memset(answer,0,SIZE_OF_RESP);
/* Sanitize inputs */
if(argv[1]==0){
printf("Usage:\t./client <host-name>\n");
exit(1);
}
/*
* Ahead of all else, make the head.
*/
//TODO write some freakin macro's
question.id[0] = 'A'; //1010
question.id[1] = 'B'; //1010
question.flags1 = '\1'; //0001
question.flags2 = '\0'; //0000
question.qdcount[0]= '\0'; //0000
question.qdcount[1]='\1'; //0001
// query get's filled in at run time
question.qtype[0] = '\0'; //0000
question.qtype[1] = '\1'; //0001
question.qclass[0] = '\0'; //0000
question.qclass[1] = '\1'; //0001
unsigned char query[19];
question.query = &query[0];
// Fill in that cruft
int i;
for(i=0;i<6;i++){
question.cruft[i]='\0'; //0000
}
build_header(&question);
printf("HEADER:\n");
_hex_print(question.query,12);
/*
* Get the query in the query.
*/
// bytes for qtype and class
build_query(&question,argv[1]);
// Print all the bytes in the DNS_HEADER, the request and the 4 bytes
// of qtype qclass data.
printf("MESSAGE:\n");
_hex_print(question.query,DNS_HEADER_SIZE+strlen(argv[1])+6);
/*
* Sending request
*/
send_request(&question,answer);
printf("RESPONSE:\n");
_hex_print(answer,512);
parse_answer(answer,&question);
return 0;
}
int _hex_print( unsigned char* array, int size){
int i;
printf("hex string: \n");
for(i=0;i<size;i++){
printf("%02hhX ",array[i]);
if((i+1)%16==0)
printf("\n");
}
printf("\n");
return 1;
}