Skip to content

Commit b9b318d

Browse files
committed
1 parent b1479db commit b9b318d

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/wifipcap/wifipcap.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "config.h" // pull in HAVE_ defines
1111

12-
#define __STDC_FORMAT_MACROS
12+
#define __STDC_FORMAT_MACROS
1313

1414
#include <stdint.h>
1515
#include <inttypes.h>
@@ -55,11 +55,11 @@ int WifiPacket::debug=0;
5555
int MAC::print_fmt(MAC::PRINT_FMT_COLON);
5656

5757
std::ostream& operator<<(std::ostream& out, const MAC& mac) {
58-
const char *fmt = MAC::print_fmt == MAC::PRINT_FMT_COLON ?
58+
const char *fmt = MAC::print_fmt == MAC::PRINT_FMT_COLON ?
5959
"%02x:%02x:%02x:%02x:%02x:%02x" :
6060
"%02x%02x%02x%02x%02x%02x";
6161
char buf[24];
62-
sprintf(buf, fmt,
62+
sprintf(buf, fmt,
6363
(int)((mac.val>>40)&0xff),
6464
(int)((mac.val>>32)&0xff),
6565
(int)((mac.val>>24)&0xff),
@@ -82,7 +82,7 @@ struct tok {
8282
};
8383

8484
#if 0
85-
static const struct tok ethertype_values[] = {
85+
static const struct tok ethertype_values[] = {
8686
{ ETHERTYPE_IP, "IPv4" },
8787
{ ETHERTYPE_MPLS, "MPLS unicast" },
8888
{ ETHERTYPE_MPLS_MULTI, "MPLS multicast" },
@@ -411,7 +411,7 @@ void WifiPacket::handle_llc(const mac_hdr_t &mac,const u_char *ptr, size_t len,u
411411
cbs->HandleLLC(*this,&hdr, ptr+8, len-8);
412412
return;
413413
}
414-
414+
415415
cbs->HandleLLCUnknown(*this,ptr, len);
416416
}
417417

@@ -492,7 +492,7 @@ const char *Wifipcap::WifiUtil::MgmtReasonCode2Txt(uint v) {
492492
///////////////////////////////////////////////////////////////////////////////
493493

494494
// Jeff: HACK -- tcpdump uses a global variable to check truncation
495-
#define TTEST2(_p, _l) ((const u_char *)&(_p) - p + (_l) <= (ssize_t)len)
495+
#define TTEST2(_p, _l) ((const u_char *)&(_p) - p + (_l) <= (ssize_t)len)
496496

497497
void WifiPacket::parse_elements(struct mgmt_body_t *pbody, const u_char *p, int offset, size_t len)
498498
{
@@ -605,7 +605,7 @@ void WifiPacket::parse_elements(struct mgmt_body_t *pbody, const u_char *p, int
605605

606606
if (pbody->tim.length <= 3)
607607
break;
608-
if (pbody->rates.length > sizeof pbody->tim.bitmap)
608+
if ((pbody->tim.length -3) > sizeof pbody->tim.bitmap)
609609
return;
610610
if (!TTEST2(*(p + offset), pbody->tim.length - 3))
611611
return;
@@ -932,7 +932,7 @@ WifiPacket::handle_deauth( const struct mgmt_header_t *pmh, const u_char *p, siz
932932
*
933933
* NOTE — this function and all that it calls should be handled as methods in WifipcapCallbacks
934934
*/
935-
935+
936936
int
937937
WifiPacket::decode_mgmt_body(u_int16_t fc, struct mgmt_header_t *pmh, const u_char *p, size_t len)
938938
{
@@ -1014,13 +1014,13 @@ int WifiPacket::decode_data_frame(const u_char * ptr, size_t len, u_int16_t fc)
10141014
if(FC_TYPE(fc)==2 && FC_SUBTYPE(fc)==8){ // quality of service?
10151015
hdr.qos = 1;
10161016
}
1017-
1017+
10181018
size_t hdrlen=0;
10191019

10201020
const MAC address1 = MAC::ether2MAC(ptr+4);
10211021
const MAC address2 = MAC::ether2MAC(ptr+10);
10221022
const MAC address3 = MAC::ether2MAC(ptr+16);
1023-
1023+
10241024
/* call the 80211 callback data callback */
10251025

10261026
if (FC_TO_DS(fc)==0 && FC_FROM_DS(fc)==0) { /* ad hoc IBSS */
@@ -1061,9 +1061,9 @@ int WifiPacket::decode_data_frame(const u_char * ptr, size_t len, u_int16_t fc)
10611061

10621062
/* Handle either the WEP or the link layer. This handles the data itself */
10631063
if (FC_WEP(fc)) {
1064-
handle_wep(ptr+hdrlen, len-hdrlen-4 );
1064+
handle_wep(ptr+hdrlen, len-hdrlen-4 );
10651065
} else {
1066-
handle_llc(hdr, ptr+hdrlen, len-hdrlen-4, fc);
1066+
handle_llc(hdr, ptr+hdrlen, len-hdrlen-4, fc);
10671067
}
10681068
return 0;
10691069
}
@@ -1121,7 +1121,7 @@ int WifiPacket::decode_ctrl_frame(const u_char * ptr, size_t len, u_int16_t fc)
11211121
cbs->Handle80211CtrlCFEnd( *this, &hdr);
11221122
break;
11231123
}
1124-
case CTRL_END_ACK: {
1124+
case CTRL_END_ACK: {
11251125
ctrl_end_ack_t hdr;
11261126
hdr.fc = fc;
11271127
hdr.duration = du;
@@ -1145,7 +1145,7 @@ int WifiPacket::decode_ctrl_frame(const u_char * ptr, size_t len, u_int16_t fc)
11451145
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
11461146
#endif
11471147

1148-
void WifiPacket::handle_80211(const u_char * pkt, size_t len /* , int pad */)
1148+
void WifiPacket::handle_80211(const u_char * pkt, size_t len /* , int pad */)
11491149
{
11501150
if (debug) std::cerr << "handle_80211(len= " << len << " ";
11511151
if (len < 2) {
@@ -1174,14 +1174,14 @@ void WifiPacket::handle_80211(const u_char * pkt, size_t len /* , int pad */)
11741174
// assume fcs is last 4 bytes (?)
11751175
u_int32_t fcs_sent = EXTRACT_32BITS(pkt+len-4);
11761176
u_int32_t fcs = crc32_802(pkt, len-4);
1177-
1177+
11781178
/*
11791179
if (fcs != fcs_sent) {
11801180
cerr << "bad fcs: ";
1181-
fprintf (stderr, "%08x != %08x\n", fcs_sent, fcs);
1181+
fprintf (stderr, "%08x != %08x\n", fcs_sent, fcs);
11821182
}
11831183
*/
1184-
1184+
11851185
fcs_ok = (fcs == fcs_sent);
11861186
}
11871187
if (cbs->Check80211FCS(*this) && fcs_ok==false){
@@ -1461,7 +1461,7 @@ void WifiPacket::handle_radiotap(const u_char *p,size_t caplen)
14611461

14621462
radiotap_hdr ohdr;
14631463
memset(&ohdr, 0, sizeof(ohdr));
1464-
1464+
14651465
/* Assume no Atheros padding between 802.11 header and body */
14661466
int pad = 0;
14671467
uint32_t *presentp;
@@ -1633,10 +1633,10 @@ void Wifipcap::Init(const char *name, bool live) {
16331633

16341634
bool gzip = !strcmp(name+slen-3, ".gz");
16351635
bool bzip = !strcmp(name+slen-4, ".bz2");
1636-
1636+
16371637
char cmd[256];
16381638
char errbuf[256];
1639-
if (gzip)
1639+
if (gzip)
16401640
sprintf(cmd, "zcat %s", name);
16411641
else if (bzip)
16421642
sprintf(cmd, "bzcat %s", name);
@@ -1688,7 +1688,7 @@ void Wifipcap::Init(const char *name, bool live) {
16881688
* It records some stats and then dispatches to the appropriate callback.
16891689
*/
16901690
void Wifipcap::handle_packet(WifipcapCallbacks *cbs,int header_type,
1691-
const struct pcap_pkthdr *header, const u_char * packet)
1691+
const struct pcap_pkthdr *header, const u_char * packet)
16921692
{
16931693
/* Record start time if we don't have it */
16941694
if (startTime == TIME_NONE) {
@@ -1701,7 +1701,7 @@ void Wifipcap::handle_packet(WifipcapCallbacks *cbs,int header_type,
17011701
int hours = (header->ts.tv_sec - startTime.tv_sec)/3600;
17021702
int days = hours/24;
17031703
int left = hours%24;
1704-
fprintf(stderr, "wifipcap: %2d days %2d hours, %10" PRId64 " pkts\n",
1704+
fprintf(stderr, "wifipcap: %2d days %2d hours, %10" PRId64 " pkts\n",
17051705
days, left, packetsProcessed);
17061706
}
17071707
lastPrintTime = header->ts;
@@ -1730,7 +1730,7 @@ void Wifipcap::handle_packet(WifipcapCallbacks *cbs,int header_type,
17301730
default:
17311731
#if 0
17321732
/// 2018-08-02: slg - I'm also not sure why this is commented out.
1733-
// try handling it as default IP assuming framing is ethernet
1733+
// try handling it as default IP assuming framing is ethernet
17341734
// (this is for testing)
17351735
pkt.handle_ip(packet,header->caplen);
17361736
#endif
@@ -1747,7 +1747,7 @@ void Wifipcap::handle_packet_callback(u_char *user, const struct pcap_pkthdr *he
17471747
Wifipcap::PcapUserData *data = reinterpret_cast<Wifipcap::PcapUserData *>(user);
17481748
data->wcap->handle_packet(data->cbs,data->header_type,header,packet);
17491749
}
1750-
1750+
17511751

17521752
const char *Wifipcap::SetFilter(const char *filter)
17531753
{
@@ -1759,12 +1759,12 @@ const char *Wifipcap::SetFilter(const char *filter)
17591759
#endif
17601760

17611761

1762-
if(pcap_compile(descr,&fp,(char *)filter,0,netp) == -1) {
1763-
return "Error calling pcap_compile";
1762+
if(pcap_compile(descr,&fp,(char *)filter,0,netp) == -1) {
1763+
return "Error calling pcap_compile";
17641764
}
1765-
1766-
if(pcap_setfilter(descr,&fp) == -1) {
1767-
return "Error setting filter";
1765+
1766+
if(pcap_setfilter(descr,&fp) == -1) {
1767+
return "Error setting filter";
17681768
}
17691769

17701770
return NULL;
@@ -1776,7 +1776,7 @@ void Wifipcap::Run(WifipcapCallbacks *cbs, int maxpkts)
17761776
/* NOTE: This needs to be fixed so that the correct handle_packet is called */
17771777

17781778
packetsProcessed = 0;
1779-
1779+
17801780
do {
17811781
PcapUserData data(this,cbs,DLT_IEEE802_11_RADIO);
17821782
pcap_loop(descr, maxpkts > 0 ? maxpkts - packetsProcessed : 0,
@@ -1786,4 +1786,3 @@ void Wifipcap::Run(WifipcapCallbacks *cbs, int maxpkts)
17861786

17871787

17881788
///////////////////////////////////////////////////////////////////////////////
1789-

0 commit comments

Comments
 (0)