aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace-dns
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-07-24 17:55:16 -0400
committerLibravatar netblue30 <netblue30@protonmail.com>2023-07-24 17:55:16 -0400
commitc4b6af8f1c48e9727eea6d91f9aae3476bae762e (patch)
tree0f18aa6851df5a6761b6991e284584642e657cae /src/fnettrace-dns
parentfnettrace: trace ICPM ECHO (ping) traffic (diff)
downloadfirejail-c4b6af8f1c48e9727eea6d91f9aae3476bae762e.tar.gz
firejail-c4b6af8f1c48e9727eea6d91f9aae3476bae762e.tar.zst
firejail-c4b6af8f1c48e9727eea6d91f9aae3476bae762e.zip
integrating nettrace dnstrace and snitrace
Diffstat (limited to 'src/fnettrace-dns')
-rw-r--r--src/fnettrace-dns/main.c16
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
29static int arg_nolocal = 0;
29static char last[512] = {'\0'}; 30static 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) {
170static const char *const usage_str = 179static 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
175static void usage(void) { 185static 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;