Permalink
Browse files

Code from Sudhar.

Has some segfault errors currently.
  • Loading branch information...
JacobBodmer committed Dec 7, 2011
1 parent 43cefaa commit 31b8836340647f22942ff85ebb93b0826e2a4ccc
Showing with 63 additions and 10 deletions.
  1. +51 −8 a3/myresolver.c
  2. +12 −2 a3/myresolver.h
View
@@ -166,6 +166,15 @@ void sendDnsMessage(struct DNS_MESSAGE* message, struct sockaddr_in* server) {
// Append class
appendToBuffer(&itr, &(cur->qclass), sizeof(cur->qclass), &packet_size);
}
+
+ struct MESSAGE_RESOURCE_RECORD * cur = message->additional;
+ // Send RR Struct for RRSIG
+ appendToBuffer(&itr, cur->name, 1, &packet_size);
+ appendToBuffer(&itr, &(cur->type), 2, &packet_size);
+ appendToBuffer(&itr, &(cur->class), 2, &packet_size);
+ appendToBuffer(&itr, &(cur->ttl), 4, &packet_size);
+ appendToBuffer(&itr, &(cur->rdlength), 2, &packet_size);
+
sendNumBytes(buf, packet_size, server);
}
@@ -462,6 +471,7 @@ void parseRdata(void** dest, char* src, int bytesParsed, RR_TYPE type, uint16_t
}
}
+
void getQuestion(struct MESSAGE_QUESTION** question, int count, int *bytesParsed, char* buf) {
if (count > 0) {
*question = (struct MESSAGE_QUESTION*)malloc(sizeof(struct MESSAGE_QUESTION) * count);
@@ -679,11 +689,24 @@ void printDnsMessage(struct DNS_MESSAGE* message) {
int sendQuery(char* hostToResolve, char* dns_server, RR_TYPE query_type, struct sockaddr_in* server) {
struct DNS_MESSAGE test_message;
test_message.header.id = htons(10);
- test_message.header.additional_count = htons(0);
+ test_message.header.additional_count = htons(1); // Set the Additional Bit for RRSIG Query
test_message.header.answer_count = htons(0);
test_message.header.description = htons(0);
test_message.header.nameserver_count = htons(0);
test_message.header.question_count = htons(1);
+
+ struct MESSAGE_RESOURCE_RECORD edns;
+ // Setting the Bits for RRSIG Struct
+ edns.name = (uint8_t *) malloc(sizeof(uint8_t));
+ (*(edns.name)) = 0x00;
+ edns.type = htons(0x0029); // From Wireshark
+ edns.class = htons(4096);
+ edns.ttl =htonl(0);
+ edns.ttl = htonl(0x00000000 | 0x80008000);
+ edns.rdlength = htons(0);
+ edns.rd_data = NULL;
+
+ test_message.additional = &edns;
test_message.question = (struct MESSAGE_QUESTION*) malloc(sizeof(struct MESSAGE_QUESTION));
@@ -697,7 +720,7 @@ int sendQuery(char* hostToResolve, char* dns_server, RR_TYPE query_type, struct
fprintf(stderr, "Trying DNS server %s\n", dns_server);
//printDnsMessage(&test_message);
sendDnsMessage(&test_message, server);
- printf("done sending... wait for reply!\n");
+ printf("Done sending... wait for reply!\n");
return 0;
}
@@ -839,8 +862,10 @@ int queryForNameAt(char* name, char* root_name, RR_TYPE query_type, struct MESSA
return RET_INVALID_RESPONSE;
} else if (ret.description.auth_answer == DNS_AA_TRUE &&
ret.description.resp_code == DNS_RCODE_NAME_ERROR) {
- fprintf(stderr, "No such name.\n");
+ fprintf(stderr, "The hostname does not exist.\n"); // Changed today 06Dec
+ exit(2);
return RET_NO_SUCH_NAME;
+
} else if (ret.description.resp_code != DNS_RCODE_NOERROR) {
fprintf(stderr, "Invalid response type.\n");
return RET_INVALID_RESPONSE;
@@ -908,7 +933,7 @@ int loopThroughRRs(char* name, char* last_root, struct MESSAGE_RESOURCE_RECORD*
int lrLen = strlen(last_root);
if (nsLen >= lrLen) {
- if (strcmp(last_root, ns + (nsLen - lrLen)) == 0) {
+ if (strcmp(ns, last_root + (nsLen - lrLen)) == 0) {

This comment has been minimized.

Show comment Hide comment
@cthrax

cthrax Dec 7, 2011

Owner

Why was this change made? I think it's wrong.

@cthrax

cthrax Dec 7, 2011

Owner

Why was this change made? I think it's wrong.

This comment has been minimized.

Show comment Hide comment
@JacobBodmer

JacobBodmer Dec 8, 2011

Collaborator

Not sure, I just threw up the code I was given. I'll change it back.

@JacobBodmer

JacobBodmer Dec 8, 2011

Collaborator

Not sure, I just threw up the code I was given. I'll change it back.

fprintf(stderr, "Attempted infinite recursion (1). Skipping.\n");
// Skip to next one in list.
continue;
@@ -1033,6 +1058,11 @@ void strtolower(char str[]) {
str[i] = str[i] + 'a' - 'A';
}
}
+ printf("Hostname entered is Lowered. \n");
+ for (i = 0; str[i] != '\0'; ++i) {
+ printf("%c",str[i]);
+ }
+ printf("\n--------------------------\n");
}
void testParseLabel() {
@@ -1087,8 +1117,8 @@ int main(int argc, char *argv[]) {
char *name = (char*)malloc(sizeof(char) * 1024);
if (argc == 1) {
- memcpy(name, "www.google.com.", 16);
- //name = "www.google.com."; //For now, simply use a hard-coded domain.
+ memcpy(name, "www.nlnetlabs.nl", 16);
+
} else if (argc == 2) {
if (strlen(argv[1]) >= 1024) {
fprintf(stderr, "Invalid hostname, too long.\n");
@@ -1109,12 +1139,25 @@ int main(int argc, char *argv[]) {
}
init();
+ /*
+ struct t {
+ int count;
+ struct MESSAGE_RESOURCE_RECORD* answers;
+ }
+ t.answers = malloc(count);
+ memcpy(t.answers, message.answers, sizeof(struct MESSAGE_RESOURCE_RECORD) * count)
+ */
struct MESSAGE_RESOURCE_RECORD* answer;
+
+
int ret = loopThroughList(name, ROOT_IP, ROOT_COUNT, MESSAGE_QTYPE_AAAA, &answer);
if (ret == RET_FOUND_ANSWER) {
- printRr(answer, 256, "FOUND ULTIMATE ANSWER\n");
+ // for (int i = 0; i < t.count; i++) {
+ // if (t.answers + i)->type == MESSAGE_QTYPE_AAAA )
+ printRr(answer, htons(256), "Answer Found.\n");
+
} else if (ret == RET_NO_SUCH_NAME) {
- printf("No record of that type.\n");
+ printf("No AAAA records are associated with the name\n");
} else {
printf("No record found.\n");
}
View
@@ -34,8 +34,8 @@ const RR_TYPE MESSAGE_QTYPE_RRSIG = 0x002E;
//QR
const uint16_t DNS_QR_MASK = 0x8000; //1000 0000 0000 0000
-const uint16_t DNS_QR_TYPE_QUERY = 0x0000; //1000 0000 0000 0000
-const uint16_t DNS_QR_TYPE_RESPONSE = 0x8000; //0000 0000 0000 0000
+const uint16_t DNS_QR_TYPE_QUERY = 0x0000; //0000 0000 0000 0000
+const uint16_t DNS_QR_TYPE_RESPONSE = 0x8000; //1000 0000 0000 0000
//opcode
const uint16_t DNS_OPCODE_MASK = 0x7800; //0111 1000 0000 0000
@@ -106,6 +106,7 @@ struct DNS_MESSAGE {
struct MESSAGE_RESOURCE_RECORD* answer;
struct MESSAGE_RESOURCE_RECORD* authority;
struct MESSAGE_RESOURCE_RECORD* additional;
+ struct MESSAGE_RESOURCE_RECORD* ends;
}__attribute__((__packed__));
struct LABEL_LIST {
@@ -166,6 +167,7 @@ struct RR_AAAA {
uint8_t ip[16];
}__attribute__((__packed__));
+
struct RR_SIG {
uint16_t type_covered;
uint8_t algorithm;
@@ -180,6 +182,14 @@ struct RR_SIG {
char* signature;
}__attribute__((__packed__));
+
+
+/*
+struct final_answer {
+ int count;
+ struct MESSAGE_RESOURCE_RECORD* answers;
+};
+*/
struct RR_KEY {
uint16_t flags;
uint8_t protocol;

0 comments on commit 31b8836

Please sign in to comment.