aboutsummaryrefslogtreecommitdiffstats
path: root/main/arpwatch/17_all_arpwatch-2.1a15-restart.patch
blob: 9c7f119df4e3fc2c625502014eab6aa33cb7934a (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
diff -Naru arpwatch-2.1a15.orig/arpwatch.c arpwatch-2.1a15/arpwatch.c
--- arpwatch-2.1a15.orig/arpwatch.c	2006-09-23 22:20:51.000000000 +0400
+++ arpwatch-2.1a15/arpwatch.c	2006-09-23 22:24:49.000000000 +0400
@@ -179,6 +179,8 @@
 	struct bpf_program code;
 	char errbuf[PCAP_ERRBUF_SIZE];
 	char* username = NULL;
+	int restart = 0;
+	int restarting_loop = 0;
 	char options[] =
 		"d"
 		"f:"
@@ -191,6 +193,7 @@
 		"p"
 		"a"
 		"u:"
+		"R:"
 		"Q"
 		"z:"
 	;
@@ -267,6 +270,10 @@
 			username = optarg;
 			break;
 
+		case 'R':
+			restart = atoi(optarg);
+			break;
+
 		case 'Q':
 			++quiet;
 			break;
@@ -285,6 +292,12 @@
 	if (optind != argc)
 		usage();
 
+	if ( username && restart ) {
+		syslog(LOG_ERR, "Please, specify either -u or -R");		
+		(void)fprintf(stderr,"Please, specify either -u or -R. See arpwatch.8\n");
+		exit(1);
+	}
+
 	if (rfilename != NULL) {
 		net = 0;
 		netmask = 0;
@@ -334,6 +347,7 @@
 		syslog(LOG_ERR, "(using current working directory)");
 	}
 
+label_restart:
 	if (rfilename != NULL) {
 		pd = pcap_open_offline(rfilename, errbuf);
 		if (pd == NULL) {
@@ -348,22 +362,30 @@
 		pd = pcap_open_live(interface, snaplen, !nopromisc, timeout, errbuf);
 		if (pd == NULL) {
 			syslog(LOG_ERR, "pcap open %s: %s", interface, errbuf);
-			exit(1);
+			if (restart) {
+				syslog(LOG_ERR, "restart in %d secs", restart);
+			} else {
+				exit(1);
+			}
+			sleep(restart);
+			goto label_restart;
 		}
 #ifdef WORDS_BIGENDIAN
 		swapped = 1;
 #endif
 	}
 
-	if ( username ) {
-		dropprivileges( username );
-	} else {
-	/*
-	 * Revert to non-privileged user after opening sockets
-	 * (not needed on most systems).
-	 */
-		setgid(getgid());
-		setuid(getuid());
+	if (!restarting_loop) {
+		if ( username && !restart ) {
+			dropprivileges( username );
+		} else {
+			/*
+			 * Revert to non-privileged user after opening sockets
+			 * (not needed on most systems).
+			 */
+			setgid(getgid());
+			setuid(getuid());
+		}
 	}
 
 	/* Must be ethernet or fddi */
@@ -386,26 +408,30 @@
 	if (rfilename == NULL)
 		syslog(LOG_INFO, "listening on %s", interface);
 
-	/* Read in database */
-	initializing = 1;
-	if (!readdata())
-		exit(1);
-	sorteinfo();
+	if (!restarting_loop) {
+		/* Read in database */
+		initializing = 1;
+		if (!readdata())
+			exit(1);
+		sorteinfo();
+	}
 #ifdef DEBUG
 	if (debug > 2) {
 		debugdump();
 		exit(0);
 	}
 #endif
-	initializing = 0;
+	if (!restarting_loop) {
+		initializing = 0;
 
-	(void)setsignal(SIGINT, die);
-	(void)setsignal(SIGTERM, die);
-	(void)setsignal(SIGHUP, die);
-	if (rfilename == NULL) {
-		(void)setsignal(SIGQUIT, checkpoint);
-		(void)setsignal(SIGALRM, checkpoint);
-		(void)alarm(CHECKPOINT);
+		(void)setsignal(SIGINT, die);
+		(void)setsignal(SIGTERM, die);
+		(void)setsignal(SIGHUP, die);
+		if (rfilename == NULL) {
+			(void)setsignal(SIGQUIT, checkpoint);
+			(void)setsignal(SIGALRM, checkpoint);
+			(void)alarm(CHECKPOINT);
+		}
 	}
 
 	switch (linktype) {
@@ -424,7 +450,15 @@
 	}
 	if (status < 0) {
 		syslog(LOG_ERR, "pcap_loop: %s", pcap_geterr(pd));
-		exit(1);
+		if (restart && rfilename == NULL) {
+			syslog(LOG_ERR, "restart in %d secs", restart);
+			++restarting_loop;
+			pcap_close(pd);
+		} else {
+			exit(1);
+		}
+		sleep(restart);
+		goto label_restart;
 	}
 	pcap_close(pd);
 	if (!dump())
@@ -851,6 +885,7 @@
 		"[-p] "
 		"[-a] "
 		"[-u username] "
+		"[-R seconds ] "
 		"[-Q ] "
 		"[-z ignorenet/ignoremask] "
 		"\n"