diff options
Diffstat (limited to 'src/fnettrace-dns/main.c')
-rw-r--r-- | src/fnettrace-dns/main.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/fnettrace-dns/main.c b/src/fnettrace-dns/main.c index 1cde1942c..6324a17db 100644 --- a/src/fnettrace-dns/main.c +++ b/src/fnettrace-dns/main.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <signal.h> | 26 | #include <signal.h> |
27 | #define MAX_BUF_SIZE (64 * 1024) | 27 | #define MAX_BUF_SIZE (64 * 1024) |
28 | 28 | ||
29 | static int arg_nolocal = 0; | ||
29 | static char last[512] = {'\0'}; | 30 | static char last[512] = {'\0'}; |
30 | 31 | ||
31 | // pkt - start of DNS layer | 32 | // pkt - start of DNS layer |
@@ -116,7 +117,7 @@ static void print_date(void) { | |||
116 | struct tm *t = localtime(&now); | 117 | struct tm *t = localtime(&now); |
117 | 118 | ||
118 | if (day != t->tm_yday) { | 119 | if (day != t->tm_yday) { |
119 | printf("\nDNS trace for %s", ctime(&now)); | 120 | printf("DNS trace for %s", ctime(&now)); |
120 | day = t->tm_yday; | 121 | day = t->tm_yday; |
121 | } | 122 | } |
122 | fflush(0); | 123 | fflush(0); |
@@ -159,6 +160,14 @@ static void run_trace(void) { | |||
159 | memcpy(&ip_src, buf + 14 + 12, 4); | 160 | memcpy(&ip_src, buf + 14 + 12, 4); |
160 | ip_src = ntohl(ip_src); | 161 | ip_src = ntohl(ip_src); |
161 | 162 | ||
163 | if (arg_nolocal) { | ||
164 | if ((ip_src & 0xff000000) == 0x7f000000 || // 127.0.0.0/8 | ||
165 | (ip_src & 0xff000000) == 0x0a000000 || // 10.0.0.0/8 | ||
166 | (ip_src & 0xffff0000) == 0xc0a80000 || // 192.168.0.0/16 | ||
167 | (ip_src & 0xfff00000) == 0xac100000) // 172.16.0.0/12 | ||
168 | continue; | ||
169 | } | ||
170 | |||
162 | // if DNS packet, extract the query | 171 | // if DNS packet, extract the query |
163 | if (port_src == 53 && protocol == 0x11) // UDP protocol | 172 | if (port_src == 53 && protocol == 0x11) // UDP protocol |
164 | print_dns(ip_src, buf + 14 + ip_hlen + 8); // IP and UDP header len | 173 | print_dns(ip_src, buf + 14 + ip_hlen + 8); // IP and UDP header len |
@@ -170,7 +179,8 @@ static void run_trace(void) { | |||
170 | static const char *const usage_str = | 179 | static const char *const usage_str = |
171 | "Usage: fnettrace-dns [OPTIONS]\n" | 180 | "Usage: fnettrace-dns [OPTIONS]\n" |
172 | "Options:\n" | 181 | "Options:\n" |
173 | " --help, -? - this help screen\n"; | 182 | " --help, -? - this help screen\n" |
183 | " --nolocal\n"; | ||
174 | 184 | ||
175 | static void usage(void) { | 185 | static void usage(void) { |
176 | puts(usage_str); | 186 | puts(usage_str); |
@@ -184,6 +194,8 @@ int main(int argc, char **argv) { | |||
184 | usage(); | 194 | usage(); |
185 | return 0; | 195 | return 0; |
186 | } | 196 | } |
197 | else if (strcmp(argv[i], "--nolocal") == 0) | ||
198 | arg_nolocal = 1; | ||
187 | else { | 199 | else { |
188 | fprintf(stderr, "Error: invalid argument\n"); | 200 | fprintf(stderr, "Error: invalid argument\n"); |
189 | return 1; | 201 | return 1; |