author | max <max> | 2003-03-04 14:04:52 (UTC) |
---|---|---|
committer | max <max> | 2003-03-04 14:04:52 (UTC) |
commit | 3adca473d5440b00e15781627e00465350e9118b (patch) (side-by-side diff) | |
tree | e60e57f10c8297eee39f9e31974f9199013c4930 /noncore/net | |
parent | 7cf53b4030437bdbd405b8b16684ba9f68e2891d (diff) | |
download | opie-3adca473d5440b00e15781627e00465350e9118b.zip opie-3adca473d5440b00e15781627e00465350e9118b.tar.gz opie-3adca473d5440b00e15781627e00465350e9118b.tar.bz2 |
start_sniff
6 files changed, 135 insertions, 34 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 3a28217..b840f17 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc @@ -11,6 +11,7 @@ #define MAXCHANNEL 13 #define CHANINTERVAL 500000 + /* Main function of wellenreiterd */ int main(int argc, char **argv) { @@ -18,7 +19,7 @@ int main(int argc, char **argv) char buffer[WL_SOCKBUF]; struct pcap_pkthdr header; struct sockaddr_in saddr; - pcap_t *handletopcap; +// pcap_t *handletopcap; wl_cardtype_t cardtype; pthread_t sub; const unsigned char *packet; @@ -40,26 +41,14 @@ int main(int argc, char **argv) if(cardtype.type < 1 || cardtype.type > 4) usage(); - /* set card into monitor mode */ - if(!card_into_monitormode(&handletopcap, cardtype.iface, - cardtype.type)) + /* Until we do not act as a read daemon, it starts the sniffer + right after startup */ + if (!start_sniffer(cardtype.iface,cardtype.type)) { - wl_logerr("Cannot initialize the wireless-card, aborting"); - exit(EXIT_FAILURE); + wl_logerr("daemon, start_sniff did not return proper, aborting"); + exit(EXIT_FAILURE); } - wl_loginfo("Set card into monitor mode"); - - /* setup pcap */ - if((handletopcap = pcap_open_live(cardtype.iface, - BUFSIZ, 1, 0, NULL)) == NULL) - { - wl_logerr("pcap_open_live() failed: %s", strerror(errno)); - exit(EXIT_FAILURE); - } - -#ifdef HAVE_PCAP_NONBLOCK - pcap_setnonblock(handletopcap, 1, NULL); -#endif + wl_loginfo ("daemon, wireless card prepared for sniffing"); /* Setup socket for incoming commands */ if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) 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 @@ -6,9 +6,9 @@ #include "cardmode.hh" #include "wl_log.hh" - +pcap_t *handletopcap; /* main card into monitor function */ -int card_into_monitormode (pcap_t **orighandle, const char *device, int cardtype) +int card_into_monitormode (const char *device, int cardtype) { char CiscoRFMON[35] = "/proc/driver/aironet/"; FILE *CISCO_CONFIG_FILE; @@ -152,6 +152,51 @@ int card_check_rfmon_datalink (const char *device) } } +/* Ipaq running familiar does not have a loopback device, we need one */ +int check_loopback() +{ + /* Checking for a loopback interface with 127.0.0.1, otherwise the other stuff seems to fail on + familiar linux on ipaq's */ + int err; + /* First generate a socket to use with iocalls */ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + { + /* In case of an error */ + wl_logerr("check_loopback, generation of a socket failed, cannot continue"); + return 0; + } + /* Fill an empty an interface structure with the right flags (UP and Promsic) */ + struct ifreq ifr; + strncpy(ifr.ifr_name, "lo",3); + + /* Get the interface flags, loopback interfaces can be detected that way */ + err = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (err < 0) + { + wl_logerr("check_loopback, could not get the flags of lo, check if you got a lo loopback interface, cannot continue"); + close(fd); + return 0; + } + /* Checking the flags for IFF_LOOPBACK flags */ + if(ifr.ifr_flags && IFF_LOOPBACK) + { + /* Yes, we do have a loopback interface....sup! */ + close(fd); + wl_loginfo ("check_loopback, check for loopback interface lo successful"); + return 1; + } + else + { + wl_logerr("check_loopback, did not found an interface lo with the IFF_LOOPBACK flag set, cannot continue"); + close(fd); + return 0; + } + /* Should never be reached */ + return 0; +} /*check_loopback */ + + /* Set card into promisc mode */ int card_set_promisc_up (const char *device) { @@ -215,16 +260,6 @@ int card_remove_promisc (const char *device) /* Fill an empty an interface structure with the right flags (UP and Promsic) */ struct ifreq ifr; -/* strncpy(ifr.ifr_name, device,10); - ifr.ifr_flags = IFF_UP + IFF_PROMISC; - err = ioctl(fd, SIOCSIFFLAGS, &ifr); - if (err < 0) - { - perror("Could not access the interface, "); - close(fd); - return 0; - } - */ /* Get the flags from the interface*/ strncpy(ifr.ifr_name, device,10); err = ioctl(fd, SIOCGIFFLAGS, &ifr); 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 @@ -38,6 +38,8 @@ extern "C" #include <pcap.h> } +extern pcap_t *handletopcap; + /* Defines, used for the card setup */ #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" #define CISCO_STATUS "/proc/driver/aironet/%s/Status" @@ -58,7 +60,8 @@ extern "C" /* Prototypes */ int card_check_rfmon_datalink (const char *device); -int card_into_monitormode (pcap_t **, const char *, int); +int card_into_monitormode (const char *, int); +int check_loopback(); int card_set_promisc_up (const char *device); int card_remove_promisc (const char *device); int card_set_channel (const char *device, int channel,int cardtype); @@ -67,7 +70,6 @@ double iw_freq2float(iw_freq * in); void iw_float2freq(double in, iw_freq * out); int card_detect_channels (char * device); - /*------------------------------------------------------------------*/ /* * Wrapper to push some Wireless Parameter in the driver 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 @@ #include "wl_log.hh" #include "wl_types.hh" #include "wl_proto.hh" +#include "cardmode.hh" + +int start_sniffer(const char *device, int cardtype ) +{ + + /* This function initialize the sniffing + 1. Check for lo interface + 2. bring it into promsicous mode and UP + 3. bring device into rfmon mode + start the pcap sniffing process. + */ + + /* Do we have the device name ? */ + if(device == NULL) + { + wl_logerr("start_sniffer, parameter \"device\" is empty, please check your config"); + return 0; + } + + /* Some Linux System does not have a loopback device lo with 127.0.0.1 so sockets could + not made correctly, let the proggie check that and proceed only if it exists. */ + if (!check_loopback()) + { + wl_logerr("start_sniffer, check_loopback failed, cannot continue without a loopback"); + return 0; + } + + /* Set the card into regulary promiscous mode first and set the UP flag, in case no ip + was given. It would work without the promisc flags but i dont like this */ + if (!card_set_promisc_up(device)) + { + wl_logerr("start_sniffer, card_set_promisc_up failed, cannot continue"); + return 0; + } + + /* Set card into the rfmon/monitoring mode */ + if (!card_into_monitormode(device,cardtype)) + { + wl_logerr("start_sniffer, cannot put wireless card into monitoring mode, aborting"); + return 0; + } + + /* setup pcap handle, used for the packet decoding etc. */ + if((handletopcap = pcap_open_live((char *) device, BUFSIZ, 1, 0, NULL)) == NULL) + { + wl_logerr("pcap_open_live() failed: %s", strerror(errno)); + return 0; + } + +#ifdef HAVE_PCAP_NONBLOCK + pcap_setnonblock(handletopcap, 1, NULL); +#endif + return 1; +} + + +int stop_sniffer(const char *device, int cardtype) +{ + /* This function terminates the sniffing + 1. get the device state + 2. remove the rfmon state + 3. Remove the promisc state + start the pcap sniffing process. + + */ + + /* Do we really have at least a lo interface with the 127.0.0.1 ? */ + return 0; + +} + /* Main function, checks packets */ void process_packets(const struct pcap_pkthdr *pkthdr, 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 @@ -40,11 +40,14 @@ struct packetinfo int ssid_len; }; +/* Function definitions */ +/* Used for stoping and starting the sniffer process */ +int start_sniffer(const char *device, int cardtype); +int stop_sniffer(const char *device, int cardtype); void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); void etheraddr_string(register const u_char *ep,char * text); int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); - int GetHeaderLength(u_int16_t fc); /* 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 @@ -38,5 +38,6 @@ typedef struct { #define WL_CONFFILE "sample.conf" #define WL_CONFBUFF 128 + #endif /* WL_TYPES_HH */ |