[PATCH 5/8] tcpdump: Close pcap dumper at program exit

Sebastian Huber sebastian.huber at embedded-brains.de
Wed May 11 06:56:38 UTC 2022


Update #4650.
---
 freebsd/contrib/tcpdump/tcpdump.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/freebsd/contrib/tcpdump/tcpdump.c b/freebsd/contrib/tcpdump/tcpdump.c
index 0438dd37..a02fa184 100644
--- a/freebsd/contrib/tcpdump/tcpdump.c
+++ b/freebsd/contrib/tcpdump/tcpdump.c
@@ -1269,6 +1269,13 @@ pcap_loop_wrapper(pcap_t *pd, int cnt, pcap_handler cb, u_char *ud)
 }
 
 #define	pcap_loop(pd, cnt, cb, ud) pcap_loop_wrapper(pd, cnt, cb, ud)
+
+static void
+destroy_pcap_dumper(void *arg)
+{
+
+	pcap_dump_close(arg);
+}
 #endif /* __rtems__ */
 int
 #ifndef __rtems__
@@ -2125,6 +2132,12 @@ main(int argc, char **argv)
 		if (Uflag)
 			pcap_dump_flush(p);
 #endif
+#ifdef __rtems__
+		if (rtems_bsd_program_add_destructor(destroy_pcap_dumper, p) ==
+		    NULL) {
+			error("cannot add destructor");
+		}
+#endif /* __rtems__ */
 	} else {
 		dlt = pcap_datalink(pd);
 		ndo->ndo_if_printer = get_if_printer(ndo, dlt);
-- 
2.35.3



More information about the devel mailing list