summaryrefslogtreecommitdiff
path: root/security/fragroute/files/patch-fragroute.c
blob: f8dc691ade5508f6004db8ffa4a25735eef258bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$NetBSD: patch-fragroute.c,v 1.1 2013/05/23 16:02:13 christos Exp $
In the unix case, don't use the obsolete libevent signal interface

--- fragroute.c.orig	2002-04-07 18:55:20.000000000 -0400
+++ fragroute.c	2013-05-23 11:59:52.000000000 -0400
@@ -36,10 +36,6 @@
 
 static struct fr_ctx 	 ctx;
 
-/* XXX - these should be in event.h */
-extern int		(*event_sigcb)(void);
-extern int		 event_gotsig;
-
 static void
 usage(void)
 {
@@ -136,6 +132,10 @@
 }
 
 #ifdef WIN32
+/* XXX - these should be in event.h */
+extern int		(*event_sigcb)(void);
+extern int		 event_gotsig;
+
 static BOOL CALLBACK
 fragroute_signal(DWORD sig)
 {
@@ -144,12 +144,25 @@
 	return (TRUE);
 }
 #else
+
 static void
-fragroute_signal(int sig)
+fragroute_signal(evutil_socket_t fd, short what, void *arg)
 {
+	int sig;
+	recv(fd, &sig, sizeof(sig), 0);
 	warnx("exiting on signal %d", sig);
-	event_gotsig++;
+	exit(sig);
 }
+
+static void
+addsignal(int sig) {
+	struct event sig_ev;
+	int got;
+
+	evsignal_set(&sig_ev, sig, fragroute_signal, &got);
+	evsignal_add(&sig_ev, NULL);
+}
+
 #endif
 
 static void
@@ -165,9 +178,6 @@
 		err(1, "couldn't initialize Winsock");
 
 	SetConsoleCtrlHandler(fragroute_signal, TRUE);
-#else
-	signal(SIGINT, fragroute_signal);
-	signal(SIGTERM, fragroute_signal);
 #endif
 	if (addr_aton(dst, &ctx.dst) < 0)
 		err(1, "destination address invalid");
@@ -178,7 +188,12 @@
 	pkt_init(128);
 	
 	event_init();
+#ifdef WIN32
 	event_sigcb = fragroute_close;
+#else
+	addsignal(SIGINT);
+	addsignal(SIGTERM);
+#endif
 	
 	if ((ctx.arp = arp_open()) == NULL ||
 	    (ctx.intf = intf_open()) == NULL ||