06f92d92c5889febf68b365cf2fb8efc4fb177a5
[openwrt.git] / package / dsniff / patches / gdbm.patch
1 diff -Nur dsniff-2.3/configure dsniff-2.3.patched/configure
2 --- dsniff-2.3/configure 2005-06-11 16:38:47.000000000 +0200
3 +++ dsniff-2.3.patched/configure 2005-06-11 16:39:26.000000000 +0200
4 @@ -16,6 +16,8 @@
5 ac_help="$ac_help
6 --with-db=DIR use Berkeley DB (with --enable-compat185) in DIR"
7 ac_help="$ac_help
8 + --with-gdbm=DIR use GNU DBM in DIR"
9 +ac_help="$ac_help
10 --with-libpcap=DIR use libpcap in DIR"
11 ac_help="$ac_help
12 --with-libnet=DIR use libnet in DIR"
13 @@ -3051,7 +3053,40 @@
14
15 fi
16
17 +echo $ac_n "checking for libgdbm""... $ac_c" 1>&6
18 +echo "configure:3059: checking for libgdbm" >&5
19 +# Check whether --with-gdbm or --without-gdbm was given.
20 +if test "${with_gdbm+set}" = set; then
21 + withval="$with_gdbm"
22 + case "$withval" in
23 + yes|no)
24 + echo "$ac_t""no" 1>&6
25 + ;;
26 + *)
27 + echo "$ac_t""$withval" 1>&6
28 + if test -f $withval/include/gdbm.h -a -f $withval/lib/libgdbm.a; then
29 + owd=`pwd`
30 + if cd $withval; then withval=`pwd`; cd $owd; fi
31 + DBINC="-I$withval/include"
32 + DBLIB="-L$withval/lib -lgdbm"
33 + else
34 + { echo "configure: error: gdbm.h or libgdbm.a not found in $withval" 1>&2; exit 1; }
35 + fi
36 + ;;
37 + esac
38 +else
39 + if test -f ${prefix}/include/gdbm.h; then
40 + LNETINC="-I${prefix}/include"
41 + LNETLIB="-L${prefix}/lib -lgdbm"
42 + elif test -f /usr/include/gdbm.h; then
43 + LNETLIB="-lgdbm"
44 + else
45 + echo "$ac_t""no" 1>&6
46 + { echo "configure: error: libgdbm not found" 1>&2; exit 1; }
47 + fi
48 + echo "$ac_t""yes" 1>&6
49
50 +fi
51
52
53 echo $ac_n "checking for libnet""... $ac_c" 1>&6
54 diff -Nur dsniff-2.3/record.c dsniff-2.3.patched/record.c
55 --- dsniff-2.3/record.c 2000-11-14 16:51:02.000000000 +0100
56 +++ dsniff-2.3.patched/record.c 2005-06-11 16:39:49.000000000 +0200
57 @@ -13,12 +13,7 @@
58 #include <stdio.h>
59 #include <time.h>
60 #include <md5.h>
61 -#ifdef HAVE_DB_185_H
62 -#define DB_LIBRARY_COMPATIBILITY_API
63 -#include <db_185.h>
64 -#elif HAVE_DB_H
65 -#include <db.h>
66 -#endif
67 +#include <gdbm.h>
68 #include <libnet.h>
69 #include "options.h"
70 #include "record.h"
71 @@ -34,7 +29,7 @@
72 struct netobj data;
73 };
74
75 -static DB *db;
76 +GDBM_FILE dbf;
77
78 static int
79 xdr_rec(XDR *xdrs, struct rec *rec)
80 @@ -86,10 +81,10 @@
81 fflush(stdout);
82 }
83
84 -static DBT *
85 +static datum
86 record_hash(struct rec *rec)
87 {
88 - static DBT key;
89 + static datum key;
90 static u_char hash[16];
91 MD5_CTX ctx;
92
93 @@ -102,16 +97,16 @@
94 MD5Update(&ctx, rec->data.n_bytes, rec->data.n_len);
95 MD5Final(hash, &ctx);
96
97 - key.data = hash;
98 - key.size = sizeof(hash);
99 + key.dptr = hash;
100 + key.dsize = sizeof(hash);
101
102 - return (&key);
103 + return (key);
104 }
105
106 static int
107 record_save(struct rec *rec)
108 {
109 - DBT *key, data;
110 + datum key, data;
111 XDR xdrs;
112 u_char buf[2048];
113
114 @@ -120,15 +115,15 @@
115 if (!xdr_rec(&xdrs, rec))
116 return (0);
117
118 - data.data = buf;
119 - data.size = xdr_getpos(&xdrs);
120 + data.dptr = buf;
121 + data.dsize = xdr_getpos(&xdrs);
122
123 xdr_destroy(&xdrs);
124
125 key = record_hash(rec);
126
127 - if (db->put(db, key, &data, R_NOOVERWRITE) == 0)
128 - db->sync(db, 0);
129 + if (gdbm_store(dbf, key, data, GDBM_INSERT) == 0)
130 + gdbm_sync(dbf);
131
132 return (1);
133 }
134 @@ -136,18 +131,22 @@
135 void
136 record_dump(void)
137 {
138 - DBT key, data;
139 + datum nextkey, data;
140 XDR xdrs;
141 struct rec rec;
142
143 - while (db->seq(db, &key, &data, R_NEXT) == 0) {
144 + data = gdbm_firstkey ( dbf );
145 + while (data.dptr) {
146 + nextkey = gdbm_nextkey ( dbf, data );
147 memset(&rec, 0, sizeof(rec));
148 - xdrmem_create(&xdrs, data.data, data.size, XDR_DECODE);
149 + xdrmem_create(&xdrs, data.dptr, data.dsize, XDR_DECODE);
150
151 if (xdr_rec(&xdrs, &rec)) {
152 record_print(&rec);
153 }
154 xdr_destroy(&xdrs);
155 + free(data.dptr);
156 + data = nextkey;
157 }
158 }
159
160 @@ -155,16 +154,23 @@
161 record_init(char *file)
162 {
163 int flags, mode;
164 -
165 + // needed for gdbm_open, which does not have the option to create
166 + // a database in memory
167 + if(file == NULL) {
168 + char *record_file = "/tmp/.dsniff.db";
169 + file = record_file;
170 + }
171 +
172 if (Opt_read) {
173 - flags = O_RDONLY;
174 + flags = GDBM_READER;
175 mode = 0;
176 }
177 else {
178 - flags = O_RDWR|O_CREAT;
179 + flags = GDBM_WRCREAT;
180 mode = S_IRUSR|S_IWUSR;
181 }
182 - if ((db = dbopen(file, flags, mode, DB_BTREE, NULL)) == NULL)
183 +
184 + if ((dbf = gdbm_open(file, 1024, flags, mode, NULL)) == NULL)
185 return (0);
186
187 return (1);
188 @@ -203,6 +209,6 @@
189 void
190 record_close(void)
191 {
192 - db->close(db);
193 + gdbm_close(dbf);
194 }
195
This page took 0.051082 seconds and 3 git commands to generate.