author | max <max> | 2003-03-04 14:04:52 (UTC) |
---|---|---|
committer | max <max> | 2003-03-04 14:04:52 (UTC) |
commit | 3adca473d5440b00e15781627e00465350e9118b (patch) (unidiff) | |
tree | e60e57f10c8297eee39f9e31974f9199013c4930 /noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |
parent | 7cf53b4030437bdbd405b8b16684ba9f68e2891d (diff) | |
download | opie-3adca473d5440b00e15781627e00465350e9118b.zip opie-3adca473d5440b00e15781627e00465350e9118b.tar.gz opie-3adca473d5440b00e15781627e00465350e9118b.tar.bz2 |
start_sniff
Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter/source/sniff.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index 6e512c4..0616a7e 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |||
@@ -10,6 +10,77 @@ | |||
10 | #include "wl_log.hh" | 10 | #include "wl_log.hh" |
11 | #include "wl_types.hh" | 11 | #include "wl_types.hh" |
12 | #include "wl_proto.hh" | 12 | #include "wl_proto.hh" |
13 | #include "cardmode.hh" | ||
14 | |||
15 | int start_sniffer(const char *device, int cardtype ) | ||
16 | { | ||
17 | |||
18 | /* This function initialize the sniffing | ||
19 | 1. Check for lo interface | ||
20 | 2. bring it into promsicous mode and UP | ||
21 | 3. bring device into rfmon mode | ||
22 | start the pcap sniffing process. | ||
23 | */ | ||
24 | |||
25 | /* Do we have the device name ? */ | ||
26 | if(device == NULL) | ||
27 | { | ||
28 | wl_logerr("start_sniffer, parameter \"device\" is empty, please check your config"); | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | /* Some Linux System does not have a loopback device lo with 127.0.0.1 so sockets could | ||
33 | not made correctly, let the proggie check that and proceed only if it exists. */ | ||
34 | if (!check_loopback()) | ||
35 | { | ||
36 | wl_logerr("start_sniffer, check_loopback failed, cannot continue without a loopback"); | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | /* Set the card into regulary promiscous mode first and set the UP flag, in case no ip | ||
41 | was given. It would work without the promisc flags but i dont like this */ | ||
42 | if (!card_set_promisc_up(device)) | ||
43 | { | ||
44 | wl_logerr("start_sniffer, card_set_promisc_up failed, cannot continue"); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | /* Set card into the rfmon/monitoring mode */ | ||
49 | if (!card_into_monitormode(device,cardtype)) | ||
50 | { | ||
51 | wl_logerr("start_sniffer, cannot put wireless card into monitoring mode, aborting"); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | /* setup pcap handle, used for the packet decoding etc. */ | ||
56 | if((handletopcap = pcap_open_live((char *) device, BUFSIZ, 1, 0, NULL)) == NULL) | ||
57 | { | ||
58 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | #ifdef HAVE_PCAP_NONBLOCK | ||
63 | pcap_setnonblock(handletopcap, 1, NULL); | ||
64 | #endif | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | |||
69 | int stop_sniffer(const char *device, int cardtype) | ||
70 | { | ||
71 | /* This function terminates the sniffing | ||
72 | 1. get the device state | ||
73 | 2. remove the rfmon state | ||
74 | 3. Remove the promisc state | ||
75 | start the pcap sniffing process. | ||
76 | |||
77 | */ | ||
78 | |||
79 | /* Do we really have at least a lo interface with the 127.0.0.1 ? */ | ||
80 | return 0; | ||
81 | |||
82 | } | ||
83 | |||
13 | 84 | ||
14 | /* Main function, checks packets */ | 85 | /* Main function, checks packets */ |
15 | void process_packets(const struct pcap_pkthdr *pkthdr, | 86 | void process_packets(const struct pcap_pkthdr *pkthdr, |