pcap_file.c

Go to the documentation of this file.
00001 /* Linux Prism II Stumbler - Utility Scan for 802_11 networks under Linux
00002  * 
00003  * Project : WifiScanner (c) 2002 Hervé Schauer Consultants
00004  * Usage : This utility is written for use with IEEE 802.11 adapters based
00005  * on Intersil's PRISM II chipset (PCMCIA).
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  *
00021  * $Id: pcap.c,v 1.3 2005/11/03 15:28:53 poggij Exp $
00022  */
00023 
00024 #include <include.h>
00025 #include <src/pcap_file.h>
00026 #include <src/wlan-ng.h>
00027 #include <src/functions.h>
00028 #include <src/crt_io.h>
00029 
00030 static char *ID = "$Id: pcap.c,v 1.3 2005/11/03 15:28:53 poggij Exp $";
00031 
00032 // All extern value you want
00033 //extern unsigned int DebugLevel;
00034 //extern UINT8 SingleChannel;
00035 //extern UINT8 TypeOfCard;
00036 extern ConfigStruct config;
00037 extern p80211_caphdr_t wlan_header;
00038 extern WINDOW *Sum_WND, *RealTime_WND;
00039 
00040 static CaptureArg ca;
00041 static char errbuf[PCAP_ERRBUF_SIZE];
00042 
00043 #define STR_MAX 80
00044 
00045 //-------------
00046 
00047 // Get packet from card
00048 int getPacketPCAP(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00049 {
00050   struct pcap_pkthdr pktHdr;
00051   u_char *ret;
00052   fd_set rs;
00053 
00054   FD_ZERO(&rs);
00055   FD_SET(0, &rs);
00056 
00057   warning("before\n");
00058   ret = (u_char *) pcap_next(ca.pcap, &pktHdr);
00059   warning("after\n");
00060 
00061   // If no problem and packet is enought big (with data)
00062   if ((ret) && (pktHdr.len >= 1)) {
00063 #if 1
00064     // Function to dump in hexa the message send or sent to the driver
00065     DumpHexPaquets(RealTime_WND, ret, 0x40);
00066 #endif
00067     memcpy_buff(buf, ret + ca.offset, pktHdr.len + 0x00);
00068     // Fill Header
00069     // TODO : find this information in any maner ?!
00070     wlan_header->version = 0;    // It's a reduced capture frame format
00071     wlan_header->length = 0;     // Not used for now
00072     wlan_header->mactime = 0;
00073     wlan_header->hosttime = 0;
00074     wlan_header->phytype = 0;    // Not used for now
00075     wlan_header->channel = 0;
00076     wlan_header->datarate = 0;   // datarate is in units of 100kbps.
00077     wlan_header->antenna = 0;    // Not used for now
00078     wlan_header->priority = 0;   // Not used for now
00079     wlan_header->ssi_type = 0;   // Not used for now
00080     wlan_header->ssi_signal = 0;
00081     wlan_header->ssi_noise = 0;
00082     wlan_header->preamble = 0;   // Not used for now
00083     wlan_header->encoding = 0;   // Not used for now
00084     return pktHdr.len;
00085   } else {
00086     return (0);                 // Noting to read
00087   }
00088 }
00089 
00090 int openPacketPCAP(char *pcap_name)
00091 {
00092   ca.pcap = pcap_open_offline(pcap_name, errbuf);
00093   if (ca.pcap) {
00094     ca.DataLink = pcap_datalink(ca.pcap);
00095     ca.offset = CalculateOffset(ca.DataLink);
00096     return NO_ERROR;
00097   }
00098   return ERROR_CANT_OPEN_PCAP;
00099 }
00100 
00101 void closePacketPCAP(void)
00102 {
00103   pcap_close(ca.pcap);
00104 }

Generated on Fri Jul 25 17:10:36 2008 for WifiScanner by  doxygen 1.5.5