diff --git a/bin/magan-armv7l b/bin/magan-armv7l deleted file mode 100755 index b7b7be9..0000000 Binary files a/bin/magan-armv7l and /dev/null differ diff --git a/bin/magan-go-linux-386 b/bin/magan-go-linux-386 deleted file mode 100755 index eeb7ebd..0000000 Binary files a/bin/magan-go-linux-386 and /dev/null differ diff --git a/bin/magan-go-linux-amd64 b/bin/magan-go-linux-amd64 deleted file mode 100755 index 8a81804..0000000 Binary files a/bin/magan-go-linux-amd64 and /dev/null differ diff --git a/bin/magan-go-linux-armv6l b/bin/magan-go-linux-armv6l deleted file mode 100755 index fddb3e6..0000000 Binary files a/bin/magan-go-linux-armv6l and /dev/null differ diff --git a/bin/magan-go-linux-armv7l b/bin/magan-go-linux-armv7l deleted file mode 100755 index e66e008..0000000 Binary files a/bin/magan-go-linux-armv7l and /dev/null differ diff --git a/bin/magan-go-win-386.exe b/bin/magan-go-win-386.exe deleted file mode 100755 index 0c2dd7c..0000000 Binary files a/bin/magan-go-win-386.exe and /dev/null differ diff --git a/bin/magan-go-win-amd64.exe b/bin/magan-go-win-amd64.exe deleted file mode 100755 index fc42e6d..0000000 Binary files a/bin/magan-go-win-amd64.exe and /dev/null differ diff --git a/bin/magan-x86_64 b/bin/magan-x86_64 deleted file mode 100755 index 0bd9e27..0000000 Binary files a/bin/magan-x86_64 and /dev/null differ diff --git a/src/magan.c b/src/magan.c index 9ed0615..c77289b 100644 --- a/src/magan.c +++ b/src/magan.c @@ -166,13 +166,15 @@ curl_version_info_data *curl_version_data; char getter_url[] = "https://dns.google.com/"; int pid; char Name[] = "Magan"; -char Version[] = "Magan/2.0h epoll+pool+cache"; +char Version[] = "Magan/3.0a"; int LISTEN_PORT = 53; int debug = 0; pthread_t udpWorkers[UDP_THREADS] = { 0 }; int udpPipe[2] = { 0 }; struct cacheStruct cache[CACHE_MAX_ITEMS] = { 0 }; +char dot[] = "."; + int sockfd = 0; int epollFD = 0; @@ -668,11 +670,7 @@ void get_reply(char *request, int PROTO, struct reply *reply, int cut_here) { struct dns_question dns_question = { 0 }; memcpy(&dns_question, r, sizeof(dns_question)); - char Google_url[bufsize] = { 0 }; - snprintf(Google_url, bufsize, "%sresolve?name=%s&type=%d", getter_url, readable, ntohs(dns_question.type)); - - //printf("Google_url: %s\n" , Google_url); - debug_print("Url: %s\n", Google_url); + uint16_t queType = ntohs(dns_question.type); int Question_Size = end + 1 + sizeof(dns_question); char Question[bufsize] = { 0 }; @@ -687,20 +685,35 @@ void get_reply(char *request, int PROTO, struct reply *reply, int cut_here) { struct dns_header reply_header = { 0 }; memcpy(&reply_header, &header, sizeof(header)); // copy header from request, + // deduce url to go for: + char url[bufsize] = { 0 }; + char *pointTo = readable; + if ((queType == 2) && (!strnlen(readable, 10))) { + // a recursive query. + pointTo = dot; + } + snprintf(url, bufsize, "%sresolve?name=%s&type=%d", getter_url, pointTo, queType); + debug_print("Url: %s\n", url); + + char *json_buffer = 0; char awkward[bufsize] = { 0 }; int gotData = 0; - - char *json_buffer = getCacheEntry(Google_url); + json_buffer = getCacheEntry(url); if (!json_buffer) { - if (doCurlStuff(Google_url, awkward)) { + if (doCurlStuff(url, awkward)) { json_buffer = awkward; gotData++; } } else { - debug_print("Cache hit for %s\n", Google_url); + debug_print("Cache hit for %s\n", url); gotData++; } + if (!json_buffer) { + // this may need an rcode 5, pivots on gotData below. + json_buffer = awkward; + } + if (gotData) { rcode = 0; reply_header.rcode = rcode; @@ -823,7 +836,6 @@ void get_reply(char *request, int PROTO, struct reply *reply, int cut_here) { char *interim_buf = (char *)json_object_get_string(name); convert(con_ns, interim_buf); int end_here = strnlen(con_ns, bufsize); - memcpy(R, con_ns, end_here); R += end_here + 1; reply->sendSize += end_here + 1; @@ -1464,27 +1476,27 @@ struct Node *get_CURLHANDLE() { // max len: ONE_K void findNthWord(char *line_in, int n, char *word) { - // since we decay, copy the incoming to another buffer - char line[bufsize] = { 0 }; - memcpy(line, line_in, strnlen(line_in, ONE_K)); - - int i = 0; - char delim[] = " "; - char *Field = word; - char *LinePtr = strtok(line, delim); - while (LinePtr) { - int _len = strnlen(LinePtr, ONE_K); - if (i == n) { - strncpy(Field, LinePtr, _len + 1); + // since we decay, copy the incoming to another buffer + char line[bufsize] = { 0 }; + memcpy(line, line_in, strnlen(line_in, ONE_K)); + + int i = 0; + char delim[] = " "; + char *Field = word; + char *LinePtr = strtok(line, delim); + while (LinePtr) { + int _len = strnlen(LinePtr, ONE_K); + if (i == n) { + strncpy(Field, LinePtr, _len + 1); // printf("[%s] nth: %d, Field: %s\n", __func__, n, Field); - break; - } + break; + } - i++; - LinePtr = strtok(NULL, delim); - } + i++; + LinePtr = strtok(NULL, delim); + } - return; + return; } int debug_print(char *format, ...) { diff --git a/src/magan_go.go b/src/magan_go.go index 61b65a0..62e318e 100644 --- a/src/magan_go.go +++ b/src/magan_go.go @@ -42,7 +42,7 @@ import ( const ( binaryName = "Magan" - version = "Magan/1.5.0a" + version = "Magan/1.6" validity = 5 * 60 // cache item validity in seconds cacheMax = 100 // Max items to keep in the cache. interval = 10 // seconds to wait for house keeping runs @@ -373,10 +373,14 @@ func gatherReply(queryBuffer []uint8) *bytes.Buffer { binary.Write(buf, binary.BigEndian, tempReply[12:qlen+12]) for i := 0; i < anCountInt; i++ { - - converted := convert(response.Answer[i].Name) - buf.Write([]byte(converted)) - + if (_type == "NS") && (theyAskedFor == ".") { + if i > 0 { + buf.WriteByte(0) + } + } else { + convertName := convert(response.Answer[i].Name) + buf.Write([]byte(convertName)) + } var dnsRRStruct dnsRRStruct dnsRRStruct.TYPE = uint16(response.Answer[i].Type) dnsRRStruct.CLASS = 1 @@ -395,6 +399,7 @@ func gatherReply(queryBuffer []uint8) *bytes.Buffer { dnsRRStruct.RDLEN = uint16(len(mehu)) binary.Write(buf, binary.BigEndian, dnsRRStruct) buf.Write([]byte(mehu)) + case 16, 99: allRaw := response.Answer[i].Data var mehu string @@ -536,9 +541,7 @@ func convert(_input string) string { j++ } } - - out := b.String() - return out + return b.String() } func print(strings string, args ...interface{}) {