-rw-r--r-- | noncore/net/wellenreiter/daemon/source/Makefile | 7 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/TODO | 1 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.cc | 3 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.hh | 4 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 50 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.cc | 41 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.hh | 8 |
7 files changed, 38 insertions, 76 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile index bcbc799..f3f41f0 100644 --- a/noncore/net/wellenreiter/daemon/source/Makefile +++ b/noncore/net/wellenreiter/daemon/source/Makefile | |||
@@ -1,33 +1,28 @@ | |||
1 | # $Id$ | 1 | # $Id$ |
2 | 2 | ||
3 | CPP = g++ | 3 | CPP = g++ |
4 | 4 | ||
5 | OPTIMFLAGS= -g | 5 | OPTIMFLAGS= -g |
6 | WARNFLAGS= -Wall -pedantic -DDEBUG | 6 | WARNFLAGS= -Wall -pedantic -DDEBUG |
7 | LDFLAGS = | 7 | LDFLAGS = |
8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a | 8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a |
9 | OBJ = daemon.o | 9 | OBJ = daemon.o cardmode.o sniffer.o |
10 | 10 | ||
11 | .SUFFIXES: | 11 | .SUFFIXES: |
12 | .PHONY: all wellenreiterd clean distclean realclean | 12 | .PHONY: all wellenreiterd clean distclean realclean |
13 | 13 | ||
14 | %.o : %.cc | 14 | %.o : %.cc |
15 | $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ | 15 | $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ |
16 | 16 | ||
17 | all:wellenreiterd | 17 | all:wellenreiterd |
18 | 18 | ||
19 | wellenreiterd:$(OBJ) | 19 | wellenreiterd:$(OBJ) |
20 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ | 20 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ |
21 | @echo Build wellenreiterd | 21 | @echo Build wellenreiterd |
22 | 22 | ||
23 | sniffer: sniffer.o cardmode.o | ||
24 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) sniffer.o cardmode.o $(LDFLAGS) $(LIBS) -o $@ | ||
25 | @echo Build sniffer | ||
26 | |||
27 | |||
28 | clean distclean realclean: | 23 | clean distclean realclean: |
29 | @rm -rf wellenreiterd *~ *.o | 24 | @rm -rf wellenreiterd *~ *.o |
30 | @echo All dependent files have been removed. | 25 | @echo All dependent files have been removed. |
31 | 26 | ||
32 | daemon.o:config.hh | 27 | daemon.o:config.hh |
33 | 28 | ||
diff --git a/noncore/net/wellenreiter/daemon/source/TODO b/noncore/net/wellenreiter/daemon/source/TODO index 39b1a05..2d72ab7 100644 --- a/noncore/net/wellenreiter/daemon/source/TODO +++ b/noncore/net/wellenreiter/daemon/source/TODO | |||
@@ -1,5 +1,4 @@ | |||
1 | implement communication protocol | 1 | implement communication protocol |
2 | security analysis | 2 | security analysis |
3 | implement sniffer (last step) | ||
4 | security analysis | 3 | security analysis |
5 | code cleanup \ No newline at end of file | 4 | code cleanup \ No newline at end of file |
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc index f84ce23..8069edc 100644 --- a/noncore/net/wellenreiter/daemon/source/cardmode.cc +++ b/noncore/net/wellenreiter/daemon/source/cardmode.cc | |||
@@ -1,43 +1,44 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #include "config.hh" | ||
3 | #include "cardmode.hh" | 4 | #include "cardmode.hh" |
4 | 5 | ||
5 | int card_into_monitormode (char *device, int cardtype) | 6 | int card_into_monitormode (char *device, int cardtype) |
6 | { | 7 | { |
7 | 8 | ||
8 | int datalink; /* used for getting the pcap datalink type */ | 9 | int datalink; /* used for getting the pcap datalink type */ |
9 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 10 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
10 | FILE *CISCO_CONFIG_FILE; | 11 | FILE *CISCO_CONFIG_FILE; |
11 | char errbuf[PCAP_ERRBUF_SIZE]; | 12 | char errbuf[PCAP_ERRBUF_SIZE]; |
12 | pcap_t *handle; | 13 | pcap_t *handle; |
13 | 14 | ||
14 | /* Checks if we have a device to sniff on */ | 15 | /* Checks if we have a device to sniff on */ |
15 | if(device == NULL) | 16 | if(device == NULL) |
16 | { | 17 | { |
17 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | 18 | printf ("Fatal error i did not have any interfaces to sniff on\n"); |
18 | return 0; | 19 | return 0; |
19 | } | 20 | } |
20 | 21 | ||
21 | /* Setting the prmiscous and up flag to the interface */ | 22 | /* Setting the prmiscous and up flag to the interface */ |
22 | if (card_set_promisc_up (device) == 0) | 23 | if (card_set_promisc_up (device) == 0) |
23 | { | 24 | { |
24 | printf ("Interface flags correctly set using ifconfig\n"); | 25 | printf ("Interface flags correctly set using ifconfig\n"); |
25 | } | 26 | } |
26 | 27 | ||
27 | /* Check the cardtype and executes the commands to go into monitor mode */ | 28 | /* Check the cardtype and executes the commands to go into monitor mode */ |
28 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ | 29 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ |
29 | { | 30 | { |
30 | /* bring the sniffer into rfmon mode */ | 31 | /* bring the sniffer into rfmon mode */ |
31 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); | 32 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); |
32 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); | 33 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); |
33 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 34 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
34 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 35 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
35 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 36 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
36 | fclose(CISCO_CONFIG_FILE); | 37 | fclose(CISCO_CONFIG_FILE); |
37 | } | 38 | } |
38 | else if (cardtype == CARD_TYPE_NG) | 39 | else if (cardtype == CARD_TYPE_NG) |
39 | { | 40 | { |
40 | char wlanngcmd[62]; | 41 | char wlanngcmd[62]; |
41 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | 42 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); |
42 | if (system (wlanngcmd) != 0) | 43 | if (system (wlanngcmd) != 0) |
43 | { | 44 | { |
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.hh b/noncore/net/wellenreiter/daemon/source/cardmode.hh index 87284a1..ecc97b1 100644 --- a/noncore/net/wellenreiter/daemon/source/cardmode.hh +++ b/noncore/net/wellenreiter/daemon/source/cardmode.hh | |||
@@ -1,36 +1,34 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef CARDMODE_HH | 3 | #ifndef CARDMODE_HH |
4 | #define CARDMODE_HH | 4 | #define CARDMODE_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <pcap.h> | 9 | #include <pcap.h> |
10 | #include <errno.h> | 10 | #include <errno.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <arpa/inet.h> | 13 | #include <arpa/inet.h> |
14 | #include <net/bpf.h> | 14 | #include <net/bpf.h> |
15 | 15 | ||
16 | #endif /* CARDMODE_HH */ | ||
17 | |||
18 | /* Defines, used for the card setup */ | 16 | /* Defines, used for the card setup */ |
19 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 17 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
20 | #define CARD_TYPE_CISCO1 | 18 | #define CARD_TYPE_CISCO1 |
21 | #define CARD_TYPE_NG2 | 19 | #define CARD_TYPE_NG2 |
22 | #define CARD_TYPE_HOSTAP3 | 20 | #define CARD_TYPE_HOSTAP3 |
23 | 21 | ||
24 | /* only for now, until we have the daemon running */ | 22 | /* only for now, until we have the daemon running */ |
25 | /*the config file should provide these information */ | 23 | /*the config file should provide these information */ |
26 | #define SNIFFER_DEVICE "wlan0" | 24 | #define SNIFFER_DEVICE "wlan0" |
27 | #define CARD_TYPE CARD_TYPE_CISCO | 25 | #define CARD_TYPE CARD_TYPE_CISCO |
28 | #define SBIN_PATH"/sbin/ifconfig %s promisc up" | 26 | #define SBIN_PATH"/sbin/ifconfig %s promisc up" |
29 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | 27 | #define WLANCTL_PATH "/sbin/wlanctl-ng" |
30 | 28 | ||
31 | /* Prototypes */ | 29 | /* Prototypes */ |
32 | 30 | ||
33 | int card_into_monitormode (char * device, int cardtype); | 31 | int card_into_monitormode (char * device, int cardtype); |
34 | int card_set_promisc_up (char * device); | 32 | int card_set_promisc_up (char * device); |
35 | 33 | ||
36 | 34 | #endif /* CARDMODE_HH */ | |
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index b3a37b6..1f9e98a 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,81 +1,95 @@ | |||
1 | /* | 1 | /* |
2 | * Startup functions of wellenreiter | 2 | * Startup functions of wellenreiter |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "config.hh" | 7 | #include "config.hh" |
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | ||
9 | 11 | ||
10 | /* Main function of wellenreiterd */ | 12 | /* Main function of wellenreiterd */ |
11 | int main(int argc, char **argv) | 13 | int main(int argc, char **argv) |
12 | { | 14 | { |
13 | int sock, maxfd, guiport=GUIPORT; | 15 | int sock, maxfd; |
14 | char guihost[]="127.0.0.1"; | ||
15 | struct sockaddr_in *cliaddr; | 16 | struct sockaddr_in *cliaddr; |
16 | socklen_t len=sizeof(struct sockaddr); | 17 | socklen_t len=sizeof(struct sockaddr); |
17 | char buffer[128]; | 18 | char buffer[128]; |
18 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 19 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
22 | const u_char *packet; /* The actual packet content*/ | ||
23 | |||
19 | fd_set rset; | 24 | fd_set rset; |
20 | 25 | ||
21 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 26 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
22 | 27 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | ||
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
30 | { | ||
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | ||
32 | exit(-1); | ||
33 | } | ||
34 | |||
35 | /* opening the pcap for sniffing */ | ||
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | ||
37 | #ifdef HAVE_PCAP_NONBLOCK | ||
38 | pcap_setnonblock(handletopcap, 1, errstr); | ||
39 | #endif | ||
40 | |||
23 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
24 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) | 42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) |
25 | { | 43 | { |
26 | wl_logerr("Cannot setup socket"); | 44 | wl_logerr("Cannot setup socket"); |
27 | exit(-1); | 45 | exit(-1); |
28 | } | 46 | } |
29 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 47 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
30 | 48 | ||
31 | FD_ZERO(&rset); | 49 | FD_ZERO(&rset); |
32 | 50 | ||
33 | /* Start main loop */ | 51 | /* Start main loop */ |
34 | wl_loginfo("Starting main loop"); | 52 | wl_loginfo("Starting main loop"); |
35 | while(1) | 53 | while(1) |
36 | { | 54 | { |
37 | 55 | ||
38 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
39 | FD_SET(fileno(fp), &rset); | 57 | FD_SET(pcap_fileno(handletopcap), &rset); |
40 | maxfd=sock+fileno(fp)+1; | 58 | maxfd=sock + pcap_fileno(handletopcap) + 1; |
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
42 | { | 60 | { |
43 | wl_logerr("Error calling select: %s", strerror(errno)); | 61 | wl_logerr("Error calling select: %s", strerror(errno)); |
44 | break; | 62 | break; |
45 | } | 63 | } |
46 | 64 | ||
47 | /* Got data on local socket from GUI */ | 65 | /* Got data on local socket from GUI */ |
48 | if(FD_ISSET(sock, &rset)) | 66 | if(FD_ISSET(sock, &rset)) |
49 | { | 67 | { |
50 | memset(buffer, 0, sizeof(buffer)); | 68 | memset(buffer, 0, sizeof(buffer)); |
51 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | 69 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) |
52 | { | 70 | { |
53 | wl_logerr("Cannot read from socket: %s", strerror(errno)); | 71 | wl_logerr("Cannot read from socket: %s", strerror(errno)); |
54 | break; | 72 | break; |
55 | } | 73 | } |
56 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | 74 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); |
57 | 75 | ||
58 | /* Pass string to analyze function */ | 76 | /* will be passed to analyze function */ |
59 | // sendcomm(guihost, guiport, buffer); | 77 | fprintf(stderr, "Received command: %s\n", buffer); |
60 | 78 | ||
61 | } | 79 | } |
62 | 80 | ||
63 | /* Will be replaced with sniffer ... later */ | 81 | /* Pcap stuff */ |
64 | if(FD_ISSET(fileno(fp), &rset)) | 82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
65 | { | 83 | { |
66 | memset(buffer, 0, sizeof(buffer)); | ||
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | ||
68 | { | ||
69 | wl_logerr("Cannot read from stdin: %s", strerror(errno)); | ||
70 | break; | ||
71 | } | ||
72 | wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer); | ||
73 | 84 | ||
74 | /* Send string to GUI */ | 85 | /* Grab one single packet */ |
75 | sendcomm(guihost, guiport, "%d: %s", 1234, buffer); | 86 | packet = pcap_next(handletopcap, &header); |
87 | |||
88 | /* process the packet */ | ||
89 | process_packets(NULL,&header,*&packet); | ||
76 | 90 | ||
77 | } | 91 | } |
78 | } | 92 | } |
79 | close(sock); | 93 | close(sock); |
80 | exit(0); | 94 | exit(0); |
81 | } | 95 | } |
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc index be64d67..66d5b6f 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.cc +++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc | |||
@@ -1,77 +1,38 @@ | |||
1 | /* | 1 | /* |
2 | * rfmon mode sniffer | 2 | * rfmon mode sniffer |
3 | * This works only with cisco wireless cards with an rfmon | 3 | * This works only with cisco wireless cards with an rfmon |
4 | * able driver and not with wifi stuff. | 4 | * able driver and not with wifi stuff. |
5 | * | 5 | * |
6 | * $Id$ | 6 | * $Id$ |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "config.hh" | 9 | #include "config.hh" |
10 | #include "cardmode.hh" | 10 | #include "cardmode.hh" |
11 | #include "sniffer.hh" | 11 | #include "sniffer.hh" |
12 | #include "ieee802_11.hh" | 12 | #include "ieee802_11.hh" |
13 | #include "extract.hh" | 13 | #include "extract.hh" |
14 | 14 | ||
15 | int main(void) | ||
16 | { | ||
17 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
18 | return 0; | ||
19 | start_sniffing (SNIFFER_DEVICE); | ||
20 | |||
21 | return 1; | ||
22 | } | ||
23 | |||
24 | int start_sniffing (char * device) | ||
25 | { | ||
26 | |||
27 | pcap_t *handletopcap; /* The handle to the libpcap */ | ||
28 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
29 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
30 | const u_char *packet; /* The actual packet content*/ | ||
31 | |||
32 | /* opening the pcap for sniffing */ | ||
33 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | ||
34 | |||
35 | #ifdef HAVE_PCAP_NONBLOCK | ||
36 | pcap_setnonblock(handletopcap, 1, errstr); | ||
37 | #endif | ||
38 | /*start scanning */ | ||
39 | //pcap_loop(handletopcap,-1,process_packets,NULL); | ||
40 | /* Loope endless */ | ||
41 | while(1) | ||
42 | { | ||
43 | /* Grab one single packet */ | ||
44 | packet = pcap_next(handletopcap, &header); | ||
45 | |||
46 | /* process the packet */ | ||
47 | process_packets(NULL,&header,*&packet); | ||
48 | } | ||
49 | |||
50 | printf("\nDone processing packets... wheew!\n"); | ||
51 | return 1; | ||
52 | } | ||
53 | |||
54 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 15 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) |
55 | { | 16 | { |
56 | u_int caplen = pkthdr->caplen; | 17 | u_int caplen = pkthdr->caplen; |
57 | u_int length = pkthdr->len; | 18 | u_int length = pkthdr->len; |
58 | u_int16_t fc; | 19 | u_int16_t fc; |
59 | u_int HEADER_LENGTH; | 20 | u_int HEADER_LENGTH; |
60 | 21 | ||
61 | /* pinfo holds all interresting information for us */ | 22 | /* pinfo holds all interresting information for us */ |
62 | struct packetinfo pinfo; | 23 | struct packetinfo pinfo; |
63 | struct packetinfo *pinfoptr; | 24 | struct packetinfo *pinfoptr; |
64 | pinfoptr=&pinfo; | 25 | pinfoptr=&pinfo; |
65 | 26 | ||
66 | pinfoptr->isvalid = 0; | 27 | pinfoptr->isvalid = 0; |
67 | pinfoptr->pktlen = pkthdr->len; | 28 | pinfoptr->pktlen = pkthdr->len; |
68 | 29 | ||
69 | if (caplen < IEEE802_11_FC_LEN) | 30 | if (caplen < IEEE802_11_FC_LEN) |
70 | { | 31 | { |
71 | /* This is a garbage packet, because is does not long enough | 32 | /* This is a garbage packet, because is does not long enough |
72 | to hold a 802.11b header */ | 33 | to hold a 802.11b header */ |
73 | pinfoptr->isvalid = 0; | 34 | pinfoptr->isvalid = 0; |
74 | return; | 35 | return; |
75 | } | 36 | } |
76 | 37 | ||
77 | /* Gets the framecontrol bits (2bytes long) */ | 38 | /* Gets the framecontrol bits (2bytes long) */ |
@@ -277,49 +238,49 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
277 | break; | 238 | break; |
278 | case E_CF: | 239 | case E_CF: |
279 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 240 | memcpy(&(pbody.cf),p+offset,8); offset +=8; |
280 | break; | 241 | break; |
281 | case E_TIM: | 242 | case E_TIM: |
282 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 243 | memcpy(&(pbody.tim),p+offset,2); offset +=2; |
283 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 244 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; |
284 | if ((pbody.tim.length -3) > 0) | 245 | if ((pbody.tim.length -3) > 0) |
285 | { | 246 | { |
286 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 247 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
287 | offset += pbody.tim.length -3; | 248 | offset += pbody.tim.length -3; |
288 | } | 249 | } |
289 | break; | 250 | break; |
290 | default: | 251 | default: |
291 | 252 | ||
292 | offset+= *(p+offset+1) + 2; | 253 | offset+= *(p+offset+1) + 2; |
293 | break; | 254 | break; |
294 | } /* end of switch*/ | 255 | } /* end of switch*/ |
295 | } /* end of for loop */ | 256 | } /* end of for loop */ |
296 | return 0; | 257 | return 0; |
297 | 258 | ||
298 | } /* End of handle_beacon */ | 259 | } /* End of handle_beacon */ |
299 | 260 | ||
300 | 261 | ||
301 | static int GetHeaderLength(u_int16_t fc) | 262 | int GetHeaderLength(u_int16_t fc) |
302 | { | 263 | { |
303 | int iLength=0; | 264 | int iLength=0; |
304 | 265 | ||
305 | switch (FC_TYPE(fc)) { | 266 | switch (FC_TYPE(fc)) { |
306 | case T_MGMT: | 267 | case T_MGMT: |
307 | iLength = MGMT_HEADER_LEN; | 268 | iLength = MGMT_HEADER_LEN; |
308 | break; | 269 | break; |
309 | case T_CTRL: | 270 | case T_CTRL: |
310 | switch (FC_SUBTYPE(fc)) { | 271 | switch (FC_SUBTYPE(fc)) { |
311 | case CTRL_PS_POLL: | 272 | case CTRL_PS_POLL: |
312 | iLength = CTRL_PS_POLL_LEN; | 273 | iLength = CTRL_PS_POLL_LEN; |
313 | break; | 274 | break; |
314 | case CTRL_RTS: | 275 | case CTRL_RTS: |
315 | iLength = CTRL_RTS_LEN; | 276 | iLength = CTRL_RTS_LEN; |
316 | break; | 277 | break; |
317 | case CTRL_CTS: | 278 | case CTRL_CTS: |
318 | iLength = CTRL_CTS_LEN; | 279 | iLength = CTRL_CTS_LEN; |
319 | break; | 280 | break; |
320 | case CTRL_ACK: | 281 | case CTRL_ACK: |
321 | iLength = CTRL_ACK_LEN; | 282 | iLength = CTRL_ACK_LEN; |
322 | break; | 283 | break; |
323 | case CTRL_CF_END: | 284 | case CTRL_CF_END: |
324 | iLength = CTRL_END_LEN; | 285 | iLength = CTRL_END_LEN; |
325 | break; | 286 | break; |
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.hh b/noncore/net/wellenreiter/daemon/source/sniffer.hh index d262353..7e1e3be 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.hh +++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh | |||
@@ -1,70 +1,64 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef SNIFFER_HH | 3 | #ifndef SNIFFER_HH |
4 | #define SNIFFER_HH | 4 | #define SNIFFER_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <pcap.h> | 9 | #include <pcap.h> |
10 | #include <errno.h> | 10 | #include <errno.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <arpa/inet.h> | 13 | #include <arpa/inet.h> |
14 | #include <net/bpf.h> | 14 | #include <net/bpf.h> |
15 | 15 | ||
16 | |||
17 | #define NONBROADCASTING "non-broadcasting" | 16 | #define NONBROADCASTING "non-broadcasting" |
18 | 17 | ||
19 | |||
20 | /* holds all the interresting data */ | 18 | /* holds all the interresting data */ |
21 | struct packetinfo | 19 | struct packetinfo |
22 | { | 20 | { |
23 | int isvalid; | 21 | int isvalid; |
24 | int pktlen; | 22 | int pktlen; |
25 | int fctype; | 23 | int fctype; |
26 | int fcsubtype; | 24 | int fcsubtype; |
27 | int fc_wep; | 25 | int fc_wep; |
28 | int cap_WEP; | 26 | int cap_WEP; |
29 | int cap_IBSS; | 27 | int cap_IBSS; |
30 | int cap_ESS; | 28 | int cap_ESS; |
31 | int channel; | 29 | int channel; |
32 | char bssid[sizeof("00:00:00:00:00:00")]; | 30 | char bssid[sizeof("00:00:00:00:00:00")]; |
33 | char desthwaddr[sizeof("00:00:00:00:00:00")]; | 31 | char desthwaddr[sizeof("00:00:00:00:00:00")]; |
34 | char sndhwaddr[sizeof("00:00:00:00:00:00")]; | 32 | char sndhwaddr[sizeof("00:00:00:00:00:00")]; |
35 | char *ssid; | 33 | char *ssid; |
36 | int ssid_len; | 34 | int ssid_len; |
37 | }; | 35 | }; |
38 | 36 | ||
39 | |||
40 | /* Prototypes */ | ||
41 | int sniffer(void); | ||
42 | int start_sniffing (char * device); | ||
43 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); | 37 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); |
44 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 38 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
45 | void etheraddr_string(register const u_char *ep,char * text); | 39 | void etheraddr_string(register const u_char *ep,char * text); |
46 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 40 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
47 | 41 | ||
48 | static int GetHeaderLength(u_int16_t fc); | 42 | int GetHeaderLength(u_int16_t fc); |
49 | 43 | ||
50 | /* | 44 | /* |
51 | * True if "l" bytes of "var" were captured. | 45 | * True if "l" bytes of "var" were captured. |
52 | * | 46 | * |
53 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large | 47 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large |
54 | * that "snapend - (l)" underflows. | 48 | * that "snapend - (l)" underflows. |
55 | * | 49 | * |
56 | * The check is for <= rather than < because "l" might be 0. | 50 | * The check is for <= rather than < because "l" might be 0. |
57 | */ | 51 | */ |
58 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ | 52 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ |
59 | (const u_char *)&(var) <= snapend - (l)) | 53 | (const u_char *)&(var) <= snapend - (l)) |
60 | 54 | ||
61 | /* True if "var" was captured */ | 55 | /* True if "var" was captured */ |
62 | #define TTEST(var) TTEST2(var, sizeof(var)) | 56 | #define TTEST(var) TTEST2(var, sizeof(var)) |
63 | 57 | ||
64 | /* Bail if "l" bytes of "var" were not captured */ | 58 | /* Bail if "l" bytes of "var" were not captured */ |
65 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc | 59 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc |
66 | 60 | ||
67 | /* Bail if "var" was not captured */ | 61 | /* Bail if "var" was not captured */ |
68 | #define TCHECK(var) TCHECK2(var, sizeof(var)) | 62 | #define TCHECK(var) TCHECK2(var, sizeof(var)) |
69 | 63 | ||
70 | #endif /* SNIFFER_HH */ | 64 | #endif /* SNIFFER_HH */ |