aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fnettrace/main.c')
-rw-r--r--src/fnettrace/main.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/fnettrace/main.c b/src/fnettrace/main.c
index 31d49d839..634d408a3 100644
--- a/src/fnettrace/main.c
+++ b/src/fnettrace/main.c
@@ -28,7 +28,7 @@ static char *arg_log = NULL;
28 28
29typedef struct hnode_t { 29typedef struct hnode_t {
30 struct hnode_t *hnext; // used for hash table and unused linked list 30 struct hnode_t *hnext; // used for hash table and unused linked list
31 struct hnode_t *dnext; // used to display stremas on the screen 31 struct hnode_t *dnext; // used to display streams on the screen
32 uint32_t ip_src; 32 uint32_t ip_src;
33 uint32_t bytes; // number of bytes received in the last display interval 33 uint32_t bytes; // number of bytes received in the last display interval
34 uint16_t port_src; 34 uint16_t port_src;
@@ -221,6 +221,37 @@ static unsigned adjust_bandwidth(unsigned bw) {
221 return (max < (sum / 2))? sum: max; 221 return (max < (sum / 2))? sum: max;
222} 222}
223 223
224static inline const char *common_port(uint16_t port) {
225 if (port > 123)
226 return NULL;
227
228 if (port == 20 || port == 21)
229 return "(FTP)";
230 else if (port == 22)
231 return "(SSH)";
232 else if (port == 23)
233 return "(telnet)";
234 else if (port == 25)
235 return "(SMTP)";
236 else if (port == 43)
237 return "(WHOIS)";
238 else if (port == 67)
239 return "(DHCP)";
240 else if (port == 69)
241 return "(TFTP)";
242 else if (port == 80)
243 return "(HTTP)";
244 else if (port == 109)
245 return "(POP2)";
246 else if (port == 110)
247 return "(POP3)";
248 else if (port == 123)
249 return "(NTP)";
250
251 return NULL;
252}
253
254
224static void hnode_print(unsigned bw) { 255static void hnode_print(unsigned bw) {
225 assert(!arg_netfilter); 256 assert(!arg_netfilter);
226 bw = (bw < 1024 * DISPLAY_INTERVAL)? 1024 * DISPLAY_INTERVAL: bw; 257 bw = (bw < 1024 * DISPLAY_INTERVAL)? 1024 * DISPLAY_INTERVAL: bw;
@@ -285,19 +316,19 @@ static void hnode_print(unsigned bw) {
285 else 316 else
286 bwline = print_bw(ptr->bytes / bwunit); 317 bwline = print_bw(ptr->bytes / bwunit);
287 318
288 char *protocol = ""; 319 const char *protocol = NULL;
289 if (ptr->port_src == 80) 320 if (ptr->port_src == 443)
290 protocol = "(HTTP)"; 321 protocol = "(TLS)";
322 else if (ptr->port_src == 53)
323 protocol = "(DNS)";
291 else if (ptr->port_src == 853) 324 else if (ptr->port_src == 853)
292 protocol = "(DoT)"; 325 protocol = "(DoT)";
326 else if ((protocol = common_port(ptr->port_src)) != NULL)
327 ;
293 else if (ptr->protocol == 0x11) 328 else if (ptr->protocol == 0x11)
294 protocol = "(UDP)"; 329 protocol = "(UDP)";
295/* 330 if (protocol == NULL)
296 else (ptr->port_src == 443) 331 protocol = "";
297 protocol = "TLS";
298 else if (ptr->port_src == 53)
299 protocol = "DNS";
300*/
301 332
302 len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u%s %s\n", 333 len = snprintf(line, LINE_MAX, "%10s %s %d.%d.%d.%d:%u%s %s\n",
303 bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->hostname); 334 bytes, bwline, PRINT_IP(ptr->ip_src), ptr->port_src, protocol, ptr->hostname);
@@ -409,7 +440,8 @@ static void run_trace(void) {
409 memcpy(&port_src, buf + hlen, 2); 440 memcpy(&port_src, buf + hlen, 2);
410 port_src = ntohs(port_src); 441 port_src = ntohs(port_src);
411 442
412 hnode_add(ip_src, buf[9], port_src, bytes + 14); 443 uint8_t protocol = buf[9];
444 hnode_add(ip_src, protocol, port_src, bytes + 14);
413 } 445 }
414 } 446 }
415 } 447 }