Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter') (more/less context) (ignore whitespace changes)
5 files changed, 127 insertions, 15 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 7c9fbc4..4f187c0 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -7,7 +7,7 @@ | |||
7 | #include "cardmode.hh" | 7 | #include "cardmode.hh" |
8 | #include "wl_log.hh" | 8 | #include "wl_log.hh" |
9 | 9 | pcap_t *handletopcap; | |
10 | /* main card into monitor function */ | 10 | /* main card into monitor function */ |
11 | int card_into_monitormode (pcap_t **orighandle, const char *device, int cardtype) | 11 | int card_into_monitormode (const char *device, int cardtype) |
12 | { | 12 | { |
13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
@@ -153,4 +153,49 @@ int card_check_rfmon_datalink (const char *device) | |||
153 | } | 153 | } |
154 | 154 | ||
155 | /* Ipaq running familiar does not have a loopback device, we need one */ | ||
156 | int check_loopback() | ||
157 | { | ||
158 | /* Checking for a loopback interface with 127.0.0.1, otherwise the other stuff seems to fail on | ||
159 | familiar linux on ipaq's */ | ||
160 | int err; | ||
161 | /* First generate a socket to use with iocalls */ | ||
162 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
163 | if (fd < 0) | ||
164 | { | ||
165 | /* In case of an error */ | ||
166 | wl_logerr("check_loopback, generation of a socket failed, cannot continue"); | ||
167 | return 0; | ||
168 | } | ||
169 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | ||
170 | struct ifreq ifr; | ||
171 | strncpy(ifr.ifr_name, "lo",3); | ||
172 | |||
173 | /* Get the interface flags, loopback interfaces can be detected that way */ | ||
174 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); | ||
175 | if (err < 0) | ||
176 | { | ||
177 | wl_logerr("check_loopback, could not get the flags of lo, check if you got a lo loopback interface, cannot continue"); | ||
178 | close(fd); | ||
179 | return 0; | ||
180 | } | ||
181 | /* Checking the flags for IFF_LOOPBACK flags */ | ||
182 | if(ifr.ifr_flags && IFF_LOOPBACK) | ||
183 | { | ||
184 | /* Yes, we do have a loopback interface....sup! */ | ||
185 | close(fd); | ||
186 | wl_loginfo ("check_loopback, check for loopback interface lo successful"); | ||
187 | return 1; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | wl_logerr("check_loopback, did not found an interface lo with the IFF_LOOPBACK flag set, cannot continue"); | ||
192 | close(fd); | ||
193 | return 0; | ||
194 | } | ||
195 | /* Should never be reached */ | ||
196 | return 0; | ||
197 | } /*check_loopback */ | ||
198 | |||
199 | |||
155 | /* Set card into promisc mode */ | 200 | /* Set card into promisc mode */ |
156 | int card_set_promisc_up (const char *device) | 201 | int card_set_promisc_up (const char *device) |
@@ -216,14 +261,4 @@ int card_remove_promisc (const char *device) | |||
216 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | 261 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ |
217 | struct ifreq ifr; | 262 | struct ifreq ifr; |
218 | /* strncpy(ifr.ifr_name, device,10); | ||
219 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | ||
220 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | ||
221 | if (err < 0) | ||
222 | { | ||
223 | perror("Could not access the interface, "); | ||
224 | close(fd); | ||
225 | return 0; | ||
226 | } | ||
227 | */ | ||
228 | /* Get the flags from the interface*/ | 263 | /* Get the flags from the interface*/ |
229 | strncpy(ifr.ifr_name, device,10); | 264 | strncpy(ifr.ifr_name, device,10); |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 58e99ac..73e0ae1 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -39,4 +39,6 @@ extern "C" | |||
39 | } | 39 | } |
40 | 40 | ||
41 | extern pcap_t *handletopcap; | ||
42 | |||
41 | /* Defines, used for the card setup */ | 43 | /* Defines, used for the card setup */ |
42 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 44 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
@@ -59,5 +61,6 @@ extern "C" | |||
59 | /* Prototypes */ | 61 | /* Prototypes */ |
60 | int card_check_rfmon_datalink (const char *device); | 62 | int card_check_rfmon_datalink (const char *device); |
61 | int card_into_monitormode (pcap_t **, const char *, int); | 63 | int card_into_monitormode (const char *, int); |
64 | int check_loopback(); | ||
62 | int card_set_promisc_up (const char *device); | 65 | int card_set_promisc_up (const char *device); |
63 | int card_remove_promisc (const char *device); | 66 | int card_remove_promisc (const char *device); |
@@ -68,5 +71,4 @@ void iw_float2freq(double in, iw_freq * out); | |||
68 | int card_detect_channels (char * device); | 71 | int card_detect_channels (char * device); |
69 | 72 | ||
70 | |||
71 | /*------------------------------------------------------------------*/ | 73 | /*------------------------------------------------------------------*/ |
72 | /* | 74 | /* |
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 | |||
@@ -11,4 +11,75 @@ | |||
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 */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh index c7108ac..a4cf4b7 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh | |||
@@ -41,9 +41,12 @@ struct packetinfo | |||
41 | }; | 41 | }; |
42 | 42 | ||
43 | /* Function definitions */ | ||
44 | /* Used for stoping and starting the sniffer process */ | ||
45 | int start_sniffer(const char *device, int cardtype); | ||
46 | int stop_sniffer(const char *device, int cardtype); | ||
43 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); | 47 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); |
44 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 48 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
45 | void etheraddr_string(register const u_char *ep,char * text); | 49 | void etheraddr_string(register const u_char *ep,char * text); |
46 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 50 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
47 | |||
48 | int GetHeaderLength(u_int16_t fc); | 51 | int GetHeaderLength(u_int16_t fc); |
49 | 52 | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh index cd482fe..afc105c 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh | |||
@@ -39,4 +39,5 @@ typedef struct { | |||
39 | #define WL_CONFBUFF 128 | 39 | #define WL_CONFBUFF 128 |
40 | 40 | ||
41 | |||
41 | #endif /* WL_TYPES_HH */ | 42 | #endif /* WL_TYPES_HH */ |
42 | 43 | ||