diff options
Diffstat (limited to 'src/fnettrace-dns/main.c')
-rw-r--r-- | src/fnettrace-dns/main.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/fnettrace-dns/main.c b/src/fnettrace-dns/main.c index 0281b5157..28c76a901 100644 --- a/src/fnettrace-dns/main.c +++ b/src/fnettrace-dns/main.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/if_ether.h> | 24 | #include <linux/if_ether.h> |
25 | #define MAX_BUF_SIZE (64 * 1024) | 25 | #define MAX_BUF_SIZE (64 * 1024) |
26 | 26 | ||
27 | static char last[512] = {'\0'}; | ||
28 | |||
27 | // pkt - start of DNS layer | 29 | // pkt - start of DNS layer |
28 | void print_dns(uint32_t ip_src, unsigned char *pkt) { | 30 | void print_dns(uint32_t ip_src, unsigned char *pkt) { |
29 | assert(pkt); | 31 | assert(pkt); |
@@ -33,6 +35,8 @@ void print_dns(uint32_t ip_src, unsigned char *pkt) { | |||
33 | time_t seconds = time(NULL); | 35 | time_t seconds = time(NULL); |
34 | struct tm *t = localtime(&seconds); | 36 | struct tm *t = localtime(&seconds); |
35 | 37 | ||
38 | int nxdomain = (*(pkt + 3) & 0x03 == 0x03)? 1: 0; | ||
39 | |||
36 | // expecting a single question count | 40 | // expecting a single question count |
37 | if (pkt[4] != 0 || pkt[5] != 1) | 41 | if (pkt[4] != 0 || pkt[5] != 1) |
38 | goto errout; | 42 | goto errout; |
@@ -49,8 +53,24 @@ void print_dns(uint32_t ip_src, unsigned char *pkt) { | |||
49 | len += delta;; | 53 | len += delta;; |
50 | ptr += delta; | 54 | ptr += delta; |
51 | } | 55 | } |
56 | if (*ptr != 0) | ||
57 | goto errout; | ||
58 | |||
59 | ptr++; | ||
60 | uint16_t type; | ||
61 | memcpy(&type, ptr, 2); | ||
62 | type = ntohs(type); | ||
63 | |||
64 | // filter output | ||
65 | char tmp[sizeof(last)]; | ||
66 | snprintf(tmp, sizeof(last), "%02d:%02d:%02d %-15s %s (type %u)%s", | ||
67 | t->tm_hour, t->tm_min, t->tm_sec, ip, pkt + 12 + 1, | ||
68 | type, (nxdomain)? " NXDOMAIN": ""); | ||
69 | if (strcmp(tmp, last)) { | ||
70 | printf("%s\n", tmp); | ||
71 | strcpy(last, tmp); | ||
72 | } | ||
52 | 73 | ||
53 | printf("%02d:%02d:%02d %15s %s\n", t->tm_hour, t->tm_min, t->tm_sec, ip, pkt + 12 + 1); | ||
54 | return; | 74 | return; |
55 | 75 | ||
56 | errout: | 76 | errout: |