summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
blob: c7108ac5dd11a2bd6496b4bbec5ec7111f0725d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* $Id$ */

#ifndef SNIFF_HH
#define SNIFF_HH

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

extern "C"
{
#include <net/bpf.h>
#include <pcap.h>  
}

#define   NONBROADCASTING "non-broadcasting"

/* holds all the interresting data */
struct packetinfo
{
  int isvalid;
  int pktlen;
  int fctype;
  int fcsubtype;
  int fc_wep;
  int cap_WEP;
  int cap_IBSS;
  int cap_ESS;
  int channel;
  char bssid[sizeof("00:00:00:00:00:00") + 1];
  char desthwaddr[sizeof("00:00:00:00:00:00") + 1];
  char sndhwaddr[sizeof("00:00:00:00:00:00") + 1];
  char ssid[128];
  int ssid_len;
};

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);

/*
 * True if  "l" bytes of "var" were captured.
 *
 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
 * that "snapend - (l)" underflows.
 *
 * The check is for <= rather than < because "l" might be 0.
 */
#define TTEST2(var, l) (snapend - (l) <= snapend && \
			(const u_char *)&(var) <= snapend - (l))

/* True if "var" was captured */
#define TTEST(var) TTEST2(var, sizeof(var))

/* Bail if "l" bytes of "var" were not captured */
#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc

/* Bail if "var" was not captured */
#define TCHECK(var) TCHECK2(var, sizeof(var))

#endif /* SNIFF_HH */