summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc
index 65c8579..be64d67 100644
--- a/noncore/net/wellenreiter/daemon/source/sniffer.cc
+++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc
@@ -3,59 +3,70 @@
* This works only with cisco wireless cards with an rfmon
* able driver and not with wifi stuff.
*
* $Id$
*/
#include "config.hh"
#include "cardmode.hh"
#include "sniffer.hh"
#include "ieee802_11.hh"
#include "extract.hh"
int main(void)
{
if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0)
return 0;
start_sniffing (SNIFFER_DEVICE);
return 1;
}
int start_sniffing (char * device)
{
- pcap_t *handletopcap;
- char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_t *handletopcap; /* The handle to the libpcap */
+ char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */
+ struct pcap_pkthdr header; /* The packet header from pcap*/
+ const u_char *packet; /* The actual packet content*/
/* opening the pcap for sniffing */
handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf);
#ifdef HAVE_PCAP_NONBLOCK
pcap_setnonblock(handletopcap, 1, errstr);
#endif
/*start scanning */
- pcap_loop(handletopcap,-1,process_packets,NULL);
+// pcap_loop(handletopcap,-1,process_packets,NULL);
+ /* Loope endless */
+ while(1)
+ {
+ /* Grab one single packet */
+ packet = pcap_next(handletopcap, &header);
+
+ /* process the packet */
+ process_packets(NULL,&header,*&packet);
+ }
printf("\nDone processing packets... wheew!\n");
return 1;
}
void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet)
{
u_int caplen = pkthdr->caplen;
u_int length = pkthdr->len;
u_int16_t fc;
u_int HEADER_LENGTH;
/* pinfo holds all interresting information for us */
struct packetinfo pinfo;
struct packetinfo *pinfoptr;
pinfoptr=&pinfo;
pinfoptr->isvalid = 0;
pinfoptr->pktlen = pkthdr->len;
if (caplen < IEEE802_11_FC_LEN)
{
/* This is a garbage packet, because is does not long enough
to hold a 802.11b header */
@@ -77,49 +88,48 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
}
/* Decode 802.11b header out of the packet */
if (decode_80211b_hdr(packet,pinfoptr) == 0)
{
/* Justification of the ofset to further process the packet */
length -= HEADER_LENGTH;
caplen -= HEADER_LENGTH;
packet += HEADER_LENGTH;
}
else
{ /* Something is wrong,could not be a correct packet */
return;
}
switch (FC_TYPE(fc))
{
/* Is it a managemnet frame? */
case T_MGMT:
switch (FC_SUBTYPE(fc))
{ /* Is it a beacon frame? */
case ST_BEACON:
if (handle_beacon(fc, packet,pinfoptr) ==0)
{
- printf ("\n\tOn network : %s",pinfoptr->ssid);
if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
{
/* Every beacon must have the broadcast as destination
so it must be a shitti packet */
pinfoptr->isvalid = 0;
return;
}
if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
{
/* Only one of both are possible, so must be
a noise packet, if this comes up */
pinfoptr->isvalid = 0;
return;
}
if (pinfoptr->channel < 1 || pinfoptr->channel > 14)
{
/* Only channels between 1 and 14 are possible
others must be noise packets */
pinfoptr->isvalid = 0;
return;
}
/* Here should be the infos to the gui issued */