aboutsummaryrefslogtreecommitdiff
path: root/net-mgmt/arpwatch-devel/files/patch-ap
blob: 2ab7e01b30c1ca437a20d6badbe0c8d7f839eb0f (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
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
--- util.c.orig	Fri Oct 13 18:49:03 2000
+++ util.c	Fri Jun 11 12:35:32 2004
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
+#include <dirent.h>

 #include "gnuc.h"
 #ifdef HAVE_OS_PROTO_H
@@ -53,8 +54,11 @@

 char *arpdir = ARPDIR;
 char *arpfile = ARPFILE;
+char *etherfile = ETHERFILE;
 char *ethercodes = ETHERCODES;

+struct ifdesc *if_desc = NULL;
+
 /* Broadcast ethernet addresses */
 u_char zero[6] = { 0, 0, 0, 0, 0, 0 };
 u_char allones[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -105,7 +109,7 @@
 dump(void)
 {
 	register int fd;
-	char oldarpfile[256], newarpfile[256];
+	char oldarpfile[256], newarpfile[256], *oldetherfile, *newetherfile;

 	(void)sprintf(oldarpfile, "%s-", arpfile);
 	(void)sprintf(newarpfile, "%s.new", arpfile);
@@ -130,6 +134,32 @@
 		syslog(LOG_ERR, "rename %s -> %s: %m", newarpfile, arpfile);
 		return(0);
 	}
+
+	/* ether info */
+	(void)asprintf(&oldetherfile, "%s-", etherfile);
+	(void)asprintf(&newetherfile, "%s.new", etherfile);
+
+	if ((fd = creat(newetherfile, 0644)) < 0) {
+		syslog(LOG_ERR, "creat(%s): %m", newetherfile);
+		return(0);
+	}
+	if ((dumpf = fdopen(fd, "w")) == NULL) {
+		syslog(LOG_ERR, "fdopen(%s): %m", newetherfile);
+		return(0);
+	}
+
+	fwrite(einfo_table, sizeof(struct einfo), et_cnt, dumpf);
+
+	(void)fclose(dumpf);
+	if (rename(etherfile, oldetherfile) < 0) {
+		syslog(LOG_ERR, "rename %s -> %s: %m", etherfile, oldetherfile);
+		return(0);
+	}
+	if (rename(newetherfile, etherfile) < 0) {
+		syslog(LOG_ERR, "rename %s -> %s: %m", newetherfile, etherfile);
+		return(0);
+	}
+
 	return(1);
 }

@@ -138,7 +168,64 @@
 readdata(void)
 {
 	register FILE *f;
+	char line[1024];
+	char buf[MAXNAMLEN];
+	char path[MAXNAMLEN + 1];
+	int len, i;
+	DIR *dirp;
+	struct dirent *dp;
+	struct ifdesc *idp;
+
+	/* interface descriptions */
+	if ((dirp = opendir(arpdir)) == NULL)
+	  {
+	    syslog(LOG_ERR, "opendir(%s)", arpdir);
+	    return(0);
+	  }
+
+	idp = if_desc = (struct ifdesc *) malloc(sizeof(struct ifdesc));
+	idp->name = idp->desc = NULL;
+	idp->next = NULL;
+
+	while ((dp = readdir(dirp)) != NULL)
+	  {
+	    if (dp->d_type == DT_LNK)
+	      {
+		for (i=0; i < dp->d_namlen; i++)
+		  path[i] = dp->d_name[i];
+
+		path[dp->d_namlen] = '\0';
+
+		if ((len = readlink(path, buf, MAXNAMLEN)) == -1)
+		  {
+		    syslog(LOG_ERR, "readlink(path) failed");
+		    return(0);
+		  }
+
+		buf[len] = '\0';
+
+		idp->next = (struct ifdesc *) malloc(sizeof(struct ifdesc));
+		idp = idp->next;
+		idp->next = NULL;
+		asprintf(&idp->name, "%s", path);
+		asprintf(&idp->desc, "%s", buf);
+	      }
+	  }
+
+	if (if_desc->next == NULL)
+	  {
+	    free(if_desc);
+	    idp = if_desc = NULL;
+	  }
+	else
+	  {
+	    idp = if_desc;
+	    if_desc = if_desc->next;
+	    free(idp);
+	    idp = NULL;
+	  }

+	/* arp.dat */
 	if ((f = fopen(arpfile, "r")) == NULL) {
 		syslog(LOG_ERR, "fopen(%s): %m", arpfile);
 		return(0);
@@ -147,6 +234,15 @@
 		(void)fclose(f);
 		return(0);
 	}
+	(void)fclose(f);
+
+	/* ether.dat */
+	if ((f = fopen(etherfile, "r")) == NULL) {
+	        syslog(LOG_ERR, "fopen(%s): %m", etherfile);
+		return(0);
+	}
+
+	et_cnt = fread(einfo_table, sizeof(struct einfo), HASHSIZE, f);
 	(void)fclose(f);

 	/* It's not fatal if we can't open the ethercodes file */