Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arne Øslebø
mapi
Commits
f041236e
Commit
f041236e
authored
Mar 18, 2006
by
Browse files
changed filter list into a hash table
git-svn-id:
file:///home/svn/mapi/trunk@395
8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent
ea35f663
Changes
1
Hide whitespace changes
Inline
Side-by-side
tracklib/gnutella.c
View file @
f041236e
...
...
@@ -49,12 +49,15 @@ struct list{
struct
filters
*
tail
;
};
#define HASHTABLESIZE 101
char
*
gnutella_strings
[
7
]
=
{
"GET /uri-res/"
,
"GNUTELLA CONNECT/"
,
"GNUTELLA/"
,
"GET /get/"
,
"GND"
,
"GNUTELLA"
,
"GIV"
};
struct
mapid_gnutella
{
int
*
shift
[
7
];
int
*
skip
[
7
];
struct
list
*
gnulist
;
struct
list
**
gnulist
;
struct
list
*
top_ten
;
};
int
isGnutella
(
mapidflib_function_instance_t
*
,
unsigned
char
*
,
int
);
...
...
@@ -64,9 +67,16 @@ static int gnutella_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
int
i
=
0
;
//printf("in init\n");
instance
->
internal_data
=
malloc
(
sizeof
(
struct
mapid_gnutella
));
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
=
(
struct
list
*
)
malloc
(
sizeof
(
struct
list
));
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
->
head
=
NULL
;
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
->
head
=
NULL
;
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
=
(
struct
list
**
)
malloc
(
sizeof
(
struct
list
*
)
*
HASHTABLESIZE
);
memset
(((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
,
0
,
(
sizeof
(
struct
list
*
)
*
HASHTABLESIZE
));
for
(
i
=
0
;
i
<
HASHTABLESIZE
;
i
++
)
{
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
[
i
]
=
(
struct
list
*
)
malloc
(
sizeof
(
struct
list
));
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
[
i
]
->
head
=
NULL
;
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
[
i
]
->
tail
=
NULL
;
}
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
top_ten
=
(
struct
list
*
)
malloc
(
sizeof
(
struct
list
));
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
top_ten
->
head
=
NULL
;
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
top_ten
->
tail
=
NULL
;
for
(
i
=
0
;
i
<
7
;
i
++
)
{
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
shift
[
i
]
=
make_shift
(
gnutella_strings
[
i
],
strlen
(
gnutella_strings
[
i
]));
...
...
@@ -81,7 +91,7 @@ int isGnutella(mapidflib_function_instance_t *instance, unsigned char *pkt, int
int
i
=
0
;
for
(
i
=
0
;
i
<
7
;
i
++
)
{
if
(
mSearch
((
unsigned
char
*
)(
pkt
),
len
,
gnutella_strings
[
i
],
strlen
(
gnutella_strings
[
i
]),
if
(
mSearch
((
char
*
)(
pkt
),
len
,
gnutella_strings
[
i
],
strlen
(
gnutella_strings
[
i
]),
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
skip
[
i
],
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
shift
[
i
]))
{
...
...
@@ -102,7 +112,7 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
unsigned
char
*
p
=
NULL
;
struct
timeval
ts
;
struct
list
*
gnulist
=
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
;
struct
list
*
*
gnulist
=
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
;
uint16_t
ethertype
;
struct
ether_header
*
ep
=
NULL
;
struct
iphdr
*
iph
=
NULL
;
...
...
@@ -113,6 +123,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
uint16_t
sp
,
dp
;
unsigned
int
hashval
=
0
;
p
=
pkt
;
// lay the Ethernet header struct over the packet data
...
...
@@ -133,6 +145,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
saddr
=
*
((
unsigned
int
*
)
&
(
iph
->
saddr
));
daddr
=
*
((
unsigned
int
*
)
&
(
iph
->
daddr
));
hashval
=
saddr
%
HASHTABLESIZE
;
p
+=
iph
->
ihl
*
4
;
if
(
iph
->
protocol
==
6
)
// TCP
...
...
@@ -156,7 +170,7 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
gettimeofday
(
&
ts
,
NULL
);
for
(
temp
=
gnulist
->
head
,
prev
=
gnulist
->
head
;
temp
!=
NULL
;
prev
=
temp
,
temp
=
temp
->
next
)
for
(
temp
=
gnulist
[
hashval
]
->
head
,
prev
=
gnulist
[
hashval
]
->
head
;
temp
!=
NULL
;
prev
=
temp
,
temp
=
temp
->
next
)
{
if
(
temp
->
protocol
==
iph
->
protocol
&&
(
...
...
@@ -168,8 +182,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
gettimeofday
(
&
(
temp
->
ts
),
NULL
);
if
(
iph
->
protocol
==
6
&&
tcph
->
fin
)
{
if
(
temp
==
gnulist
->
head
)
{
gnulist
->
head
=
temp
->
next
;
if
(
temp
==
gnulist
[
hashval
]
->
head
)
{
gnulist
[
hashval
]
->
head
=
temp
->
next
;
}
else
{
prev
->
next
=
temp
->
next
;
...
...
@@ -181,8 +195,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
return
1
;
}
else
if
(
ts
.
tv_sec
-
temp
->
ts
.
tv_sec
>
1
)
{
if
(
temp
==
gnulist
->
head
)
{
gnulist
->
head
=
temp
->
next
;
if
(
temp
==
gnulist
[
hashval
]
->
head
)
{
gnulist
[
hashval
]
->
head
=
temp
->
next
;
}
else
{
prev
->
next
=
temp
->
next
;
...
...
@@ -203,8 +217,11 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
new
->
daddr
=
daddr
;
new
->
sp
=
sp
;
new
->
dp
=
dp
;
hashval
=
new
->
saddr
%
HASHTABLESIZE
;
for
(
temp
=
gnulist
->
head
;
temp
!=
NULL
;
temp
=
temp
->
next
)
for
(
temp
=
gnulist
[
hashval
]
->
head
;
temp
!=
NULL
;
temp
=
temp
->
next
)
{
if
(
new
->
protocol
==
temp
->
protocol
&&
(
(
new
->
saddr
==
temp
->
saddr
&&
new
->
daddr
==
temp
->
daddr
&&
new
->
sp
==
temp
->
sp
&&
new
->
dp
==
temp
->
dp
)
...
...
@@ -217,8 +234,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
}
}
new
->
next
=
gnulist
->
head
;
gnulist
->
head
=
new
;
new
->
next
=
gnulist
[
hashval
]
->
head
;
gnulist
[
hashval
]
->
head
=
new
;
return
1
;
}
...
...
@@ -229,17 +246,30 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
static
int
gnutella_cleanup
(
mapidflib_function_instance_t
*
instance
)
{
struct
filters
*
temp
=
NULL
,
*
tmp
=
NULL
;
int
i
=
0
;
if
(
instance
->
internal_data
!=
NULL
){
temp
=
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
->
head
;
while
(
temp
!=
NULL
)
{
tmp
=
temp
;
temp
=
temp
->
next
;
free
(
tmp
);
}
for
(
i
=
0
;
i
<
HASHTABLESIZE
;
i
++
)
{
temp
=
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
[
i
]
->
head
;
while
(
temp
!=
NULL
)
{
tmp
=
temp
;
temp
=
temp
->
next
;
free
(
tmp
);
}
}
temp
=
((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
top_ten
->
head
;
while
(
temp
!=
NULL
)
{
tmp
=
temp
;
temp
=
temp
->
next
;
free
(
tmp
);
}
free
(((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
gnulist
);
free
(((
struct
mapid_gnutella
*
)
instance
->
internal_data
)
->
top_ten
);
free
(
instance
->
internal_data
);
}
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment