summaryrefslogtreecommitdiff
authormax <max>2002-11-23 20:33:08 (UTC)
committer max <max>2002-11-23 20:33:08 (UTC)
commitf673a2924c8d3495a99e0eba7073a3419dd937bf (patch) (side-by-side diff)
treefdd5e641fef00d8e087bbec5a741a24ec2f80f62
parent2f11392ab9292df21a6e1374800954a6b405ee9b (diff)
downloadopie-f673a2924c8d3495a99e0eba7073a3419dd937bf.zip
opie-f673a2924c8d3495a99e0eba7073a3419dd937bf.tar.gz
opie-f673a2924c8d3495a99e0eba7073a3419dd937bf.tar.bz2
Sniffer changed to pcap_next
Diffstat (more/less context) (show 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
@@ -1,133 +1,143 @@
/*
* rfmon mode sniffer
* 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 */
pinfoptr->isvalid = 0;
return;
}
/* Gets the framecontrol bits (2bytes long) */
fc = EXTRACT_LE_16BITS(packet);
HEADER_LENGTH = GetHeaderLength(fc);
if (caplen < HEADER_LENGTH)
{
/* This is a garbage packet, because it is not long enough
to hold a correct header of its type */
pinfoptr->isvalid = 0;
return;
}
/* 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 */
if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0)
{
printf ("\nHave found an accesspoint:");
}
else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1)
{
printf ("\nHave found an AD-HOC station:");