summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/Makefile31
-rw-r--r--noncore/net/wellenreiter/daemon/source/README5
-rw-r--r--noncore/net/wellenreiter/daemon/source/TODO5
-rw-r--r--noncore/net/wellenreiter/daemon/source/config.hh22
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc82
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.hh16
-rw-r--r--noncore/net/wellenreiter/daemon/source/extract.hh (renamed from noncore/net/wellenreiter/daemon/source/extract.h)9
-rw-r--r--noncore/net/wellenreiter/daemon/source/getgui.cc43
-rw-r--r--noncore/net/wellenreiter/daemon/source/getgui.hh16
-rw-r--r--noncore/net/wellenreiter/daemon/source/ieee802_11.hh (renamed from noncore/net/wellenreiter/daemon/source/ieee802_11.h)7
-rw-r--r--noncore/net/wellenreiter/daemon/source/log.cc52
-rw-r--r--noncore/net/wellenreiter/daemon/source/log.hh14
-rw-r--r--noncore/net/wellenreiter/daemon/source/sendgui.cc75
-rw-r--r--noncore/net/wellenreiter/daemon/source/sendgui.hh20
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.cc (renamed from noncore/net/wellenreiter/daemon/source/sniffer.c)98
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.hh (renamed from noncore/net/wellenreiter/daemon/source/sniffer.h)35
16 files changed, 437 insertions, 93 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile
new file mode 100644
index 0000000..dc459af
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/Makefile
@@ -0,0 +1,31 @@
1# $Id$
2
3 CPP = g++
4
5 CFLAGS=
6 OPTIMFLAGS= -g
7 WARNFLAGS= -Wall -pedantic -DDEBUG
8 LDFLAGS =
9 LIBS = -lpcap
10 OBJ = daemon.o log.o sendgui.o getgui.o sniffer.o
11
12.SUFFIXES:
13 .PHONY: all wellenreiterd clean distclean realclean
14
15%.o : %.cc
16 $(CPP) $(CFLAGS) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@
17
18 all:wellenreiterd
19
20 wellenreiterd:$(OBJ)
21 $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(CFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@
22 @echo Build wellenreiterd
23
24clean distclean realclean:
25 @rm -rf wellenreiterd *~ *.o
26 @echo All dependent files have been removed.
27
28 wellenreiterd.o:config.hh
29 serve.o: config.hh
30 log.o: config.hh
31 sendgui.o: config.hh
diff --git a/noncore/net/wellenreiter/daemon/source/README b/noncore/net/wellenreiter/daemon/source/README
deleted file mode 100644
index 249d950..0000000
--- a/noncore/net/wellenreiter/daemon/source/README
+++ b/dev/null
@@ -1,5 +0,0 @@
1compile it using:
2
3gcc -o sniffer ./sniffer.c -lpcap
4
5
diff --git a/noncore/net/wellenreiter/daemon/source/TODO b/noncore/net/wellenreiter/daemon/source/TODO
new file mode 100644
index 0000000..39b1a05
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/TODO
@@ -0,0 +1,5 @@
1implement communication protocol
2security analysis
3implement sniffer (last step)
4security analysis
5code cleanup \ No newline at end of file
diff --git a/noncore/net/wellenreiter/daemon/source/config.hh b/noncore/net/wellenreiter/daemon/source/config.hh
new file mode 100644
index 0000000..b124f41
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/config.hh
@@ -0,0 +1,22 @@
1/*
2 *
3 * Global configuration for wellenreiter
4 *
5 * $Id$
6 *
7 * Written by Martin J. Muench <mjm@codito.de>
8 *
9 */
10
11#ifndef CONFIG_HH
12#define CONFIG_HH
13
14#define PROGNAME "wellenreiter" /* Name of program (for syslog et.al.) */
15#define VERSION "0.2" /* Version of wellenreiter */
16
17#define DAEMONPORT 37772 /* Port of Daemon */
18
19#define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */
20#define GUIPORT 37773 /* Port of GUI, " " */
21
22#endif /* CONFIG_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
new file mode 100644
index 0000000..7972c0f
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -0,0 +1,82 @@
1/*
2 * Startup functions of wellenreiter
3 *
4 * $Id$
5 */
6
7#include "config.hh"
8#include "daemon.hh"
9#include "log.hh"
10#include "sendgui.hh"
11#include "getgui.hh"
12
13/* Main function of wellenreiterd */
14int main(int argc, char **argv)
15{
16 int sock, maxfd;
17 struct sockaddr_in *cliaddr;
18 socklen_t len=sizeof(struct sockaddr);
19 char buffer[128];
20 FILE *fp=stdin; /* Will be replaced with sniffer */
21 fd_set rset;
22
23 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
24
25 /* Setup socket for incoming commands */
26 if(!commsock(&sock))
27 return 0;
28
29 log_info("Set up socket '%d' for GUI communication", sock);
30
31 FD_ZERO(&rset);
32
33 /* Start main loop */
34 log_info("Starting main loop");
35 while(1)
36 {
37
38 FD_SET(sock, &rset);
39 FD_SET(fileno(fp), &rset);
40 maxfd=sock+fileno(fp)+1;
41 if(select(maxfd, &rset, NULL, NULL, NULL) < 0)
42 {
43 log_err("Error calling select: %s", strerror(errno));
44 break;
45 }
46
47 /* Got data on local socket from GUI */
48 if(FD_ISSET(sock, &rset))
49 {
50 memset(buffer, 0, sizeof(buffer));
51 if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0)
52 {
53 log_err("Cannot read from socket: %s", strerror(errno));
54 break;
55 }
56 log_info("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer);
57
58 /* Pass string to analyze function */
59 commstring(buffer);
60
61 }
62
63 /* Will be replaced with sniffer ... later */
64 if(FD_ISSET(fileno(fp), &rset))
65 {
66 memset(buffer, 0, sizeof(buffer));
67 if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL)
68 {
69 log_err("Cannot read from stdin: %s", strerror(errno));
70 break;
71 }
72
73 /* Send string to GUI */
74 sendgui("%d: %s", 1234, buffer);
75
76 }
77
78 }
79
80 close(sock);
81 return 0;
82}
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh
new file mode 100644
index 0000000..6776d37
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/daemon.hh
@@ -0,0 +1,16 @@
1/* $Id$ */
2
3#ifndef DAEMON_HH
4#define DAEMON_HH
5
6#include <stdio.h>
7#include <string.h>
8#include <sys/types.h>
9#include <sys/time.h>
10#include <sys/socket.h>
11#include <netinet/in.h>
12#include <arpa/inet.h>
13#include <unistd.h>
14#include <errno.h>
15
16#endif /* DAEMON_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/extract.h b/noncore/net/wellenreiter/daemon/source/extract.hh
index c1bcdcd..21dcffa 100644
--- a/noncore/net/wellenreiter/daemon/source/extract.h
+++ b/noncore/net/wellenreiter/daemon/source/extract.hh
@@ -1,57 +1,60 @@
1/* $Id */
1/* 2/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996 3 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 *The Regents of the University of California. All rights reserved. 4 *The Regents of the University of California. All rights reserved.
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions 7 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and 9 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials 10 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning 11 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement: 12 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California, 13 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse 15 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior 16 * or promote products derived from this software without specific prior
16 * written permission. 17 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * @(#) $Header$ (LBL)
22 */ 21 */
23
24/* Network to host order macros */ 22/* Network to host order macros */
25 23
24#ifndef EXTRACT_HH
25#define EXTRACT_HH
26
26#ifdef LBL_ALIGN 27#ifdef LBL_ALIGN
27#define EXTRACT_16BITS(p) \ 28#define EXTRACT_16BITS(p) \
28 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 29 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
29 (u_int16_t)*((const u_int8_t *)(p) + 1))) 30 (u_int16_t)*((const u_int8_t *)(p) + 1)))
30#define EXTRACT_32BITS(p) \ 31#define EXTRACT_32BITS(p) \
31 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 32 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
32 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 33 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
33 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 34 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
34 (u_int32_t)*((const u_int8_t *)(p) + 3))) 35 (u_int32_t)*((const u_int8_t *)(p) + 3)))
35#else 36#else
36#define EXTRACT_16BITS(p) \ 37#define EXTRACT_16BITS(p) \
37 ((u_int16_t)ntohs(*(const u_int16_t *)(p))) 38 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
38#define EXTRACT_32BITS(p) \ 39#define EXTRACT_32BITS(p) \
39 ((u_int32_t)ntohl(*(const u_int32_t *)(p))) 40 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
40#endif 41#endif
41 42
42#define EXTRACT_24BITS(p) \ 43#define EXTRACT_24BITS(p) \
43 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 44 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
44 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 45 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
45 (u_int32_t)*((const u_int8_t *)(p) + 2))) 46 (u_int32_t)*((const u_int8_t *)(p) + 2)))
46 47
47/* Little endian protocol host order macros */ 48/* Little endian protocol host order macros */
48 49
49#define EXTRACT_LE_8BITS(p) (*(p)) 50#define EXTRACT_LE_8BITS(p) (*(p))
50#define EXTRACT_LE_16BITS(p) \ 51#define EXTRACT_LE_16BITS(p) \
51 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ 52 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
52 (u_int16_t)*((const u_int8_t *)(p) + 0))) 53 (u_int16_t)*((const u_int8_t *)(p) + 0)))
53#define EXTRACT_LE_32BITS(p) \ 54#define EXTRACT_LE_32BITS(p) \
54 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ 55 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
55 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ 56 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
56 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 57 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
57 (u_int32_t)*((const u_int8_t *)(p) + 0))) 58 (u_int32_t)*((const u_int8_t *)(p) + 0)))
59
60#endif /* EXTRACT_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/getgui.cc b/noncore/net/wellenreiter/daemon/source/getgui.cc
new file mode 100644
index 0000000..f56f40b
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/getgui.cc
@@ -0,0 +1,43 @@
1/*
2 * Setup UDP socket for commands
3 * Misc wrapper functions for incoming commands
4 *
5 * $Id$
6 */
7
8#include "config.hh"
9#include "getgui.hh"
10#include "log.hh"
11
12struct sockaddr_in saddr;
13
14/* Setup UDP Socket for incoming commands */
15int commsock(int *sock)
16{
17
18 if((*sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
19 {
20 log_err("Cannot set up socket: %s", strerror(errno));
21 return 0;
22 }
23
24 memset(&saddr, 0, sizeof(saddr));
25 saddr.sin_family = PF_INET;
26 saddr.sin_port = htons(DAEMONPORT);
27 saddr.sin_addr.s_addr = htonl(INADDR_ANY);
28
29 if(bind(*sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0)
30 {
31 log_err("Cannot bind socket: %s", strerror(errno));
32 close(*sock);
33 return 0;
34 }
35
36 return 1;
37}
38
39int commstring(const char *input)
40{
41
42 return 1;
43}
diff --git a/noncore/net/wellenreiter/daemon/source/getgui.hh b/noncore/net/wellenreiter/daemon/source/getgui.hh
new file mode 100644
index 0000000..f5a37f9
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/getgui.hh
@@ -0,0 +1,16 @@
1/* $id */
2
3#ifndef GETGUI_HH
4#define GETGUI_HH
5
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <string.h>
10#include <unistd.h>
11#include <errno.h>
12
13int commsock(int *);
14int commstring(const char *);
15
16#endif /* GETGUI_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/ieee802_11.h b/noncore/net/wellenreiter/daemon/source/ieee802_11.hh
index 497e6ed..3cc5343 100644
--- a/noncore/net/wellenreiter/daemon/source/ieee802_11.h
+++ b/noncore/net/wellenreiter/daemon/source/ieee802_11.hh
@@ -1,47 +1,50 @@
1/* @(#) $Header$ (LBL) */ 1/* $Id$ */
2/* 2/*
3 * Copyright (c) 2001 3 * Copyright (c) 2001
4 *Fortress Technologies 4 *Fortress Technologies
5 * Charlie Lenahan ( clenahan@fortresstech.com ) 5 * Charlie Lenahan ( clenahan@fortresstech.com )
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions 8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2) 9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and 10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials 11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning 12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement: 13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California, 14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse 16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior 17 * or promote products derived from this software without specific prior
18 * written permission. 18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */ 22 */
23 23
24#ifndef IEEE802_11_HH
25#define IEEE802_11_HH
26
24 #define IEEE802_11_FC_LEN2 27 #define IEEE802_11_FC_LEN2
25 28
26#define T_MGMT 0x0 /* management */ 29#define T_MGMT 0x0 /* management */
27#define T_CTRL 0x1 /* control */ 30#define T_CTRL 0x1 /* control */
28#define T_DATA 0x2 /* data */ 31#define T_DATA 0x2 /* data */
29#define T_RESV 0x3 /* reserved */ 32#define T_RESV 0x3 /* reserved */
30 33
31 #define ST_ASSOC_REQUEST 0x0 34 #define ST_ASSOC_REQUEST 0x0
32 #define ST_ASSOC_RESPONSE 0x1 35 #define ST_ASSOC_RESPONSE 0x1
33 #define ST_REASSOC_REQUEST 0x2 36 #define ST_REASSOC_REQUEST 0x2
34 #define ST_REASSOC_RESPONSE 0x3 37 #define ST_REASSOC_RESPONSE 0x3
35 #define ST_PROBE_REQUEST 0x4 38 #define ST_PROBE_REQUEST 0x4
36 #define ST_PROBE_RESPONSE 0x5 39 #define ST_PROBE_RESPONSE 0x5
37 /* RESERVED 0x6 */ 40 /* RESERVED 0x6 */
38 /* RESERVED 0x7 */ 41 /* RESERVED 0x7 */
39 #define ST_BEACON 0x8 42 #define ST_BEACON 0x8
40 #define ST_ATIM 0x9 43 #define ST_ATIM 0x9
41 #define ST_DISASSOC 0xA 44 #define ST_DISASSOC 0xA
42 #define ST_AUTH 0xB 45 #define ST_AUTH 0xB
43 #define ST_DEAUTH 0xC 46 #define ST_DEAUTH 0xC
44 /* RESERVED 0xD */ 47 /* RESERVED 0xD */
45 /* RESERVED 0xE */ 48 /* RESERVED 0xE */
46 /* RESERVED 0xF */ 49 /* RESERVED 0xF */
47 50
@@ -222,24 +225,26 @@ struct ctrl_ps_poll_t {
222 225
223struct ctrl_end_t { 226struct ctrl_end_t {
224 u_int16_tfc; 227 u_int16_tfc;
225 u_int16_tduration; 228 u_int16_tduration;
226 u_int8_tra[6]; 229 u_int8_tra[6];
227 u_int8_tbssid[6]; 230 u_int8_tbssid[6];
228 u_int8_tfcs[4]; 231 u_int8_tfcs[4];
229}; 232};
230 233
231 #define CTRL_END_LEN(2+2+6+6+4) 234 #define CTRL_END_LEN(2+2+6+6+4)
232 235
233struct ctrl_end_ack_t { 236struct ctrl_end_ack_t {
234 u_int16_tfc; 237 u_int16_tfc;
235 u_int16_tduration; 238 u_int16_tduration;
236 u_int8_tra[6]; 239 u_int8_tra[6];
237 u_int8_tbssid[6]; 240 u_int8_tbssid[6];
238 u_int8_tfcs[4]; 241 u_int8_tfcs[4];
239}; 242};
240 243
241 #define CTRL_END_ACK_LEN(2+2+6+6+4) 244 #define CTRL_END_ACK_LEN(2+2+6+6+4)
242 245
243 #define IV_IV(iv)((iv) & 0xFFFFFF) 246 #define IV_IV(iv)((iv) & 0xFFFFFF)
244 #define IV_PAD(iv)(((iv) >> 24) & 0x3F) 247 #define IV_PAD(iv)(((iv) >> 24) & 0x3F)
245 #define IV_KEYID(iv)(((iv) >> 30) & 0x03) 248 #define IV_KEYID(iv)(((iv) >> 30) & 0x03)
249
250#endif /* IEEE802_11_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/log.cc b/noncore/net/wellenreiter/daemon/source/log.cc
new file mode 100644
index 0000000..47589d2
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/log.cc
@@ -0,0 +1,52 @@
1/*
2 * Small functions to log to syslog
3 *
4 * $Id$
5 */
6
7#include "config.hh"
8#include "log.hh"
9
10/* Log to syslog INFO */
11void log_info(const char *fmt,...)
12{
13
14 char buffer[4096];
15 va_list ap;
16
17 memset(buffer, 0, sizeof(buffer)),
18 va_start(ap, fmt);
19 vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
20 va_end(ap);
21
22 openlog(PROGNAME, LOG_PID, LOG_SYSLOG);
23 syslog(LOG_INFO, "(info) %s", buffer);
24 closelog();
25
26#ifdef DEBUG
27 fprintf(stderr, "(info) %s\n", buffer);
28#endif
29
30}
31
32/* Log to syslog ERR */
33void log_err(const char *fmt,...)
34{
35
36 char buffer[4096];
37 va_list ap;
38
39 memset(buffer, 0, sizeof(buffer));
40 va_start(ap, fmt);
41 vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
42 va_end(ap);
43
44 openlog(PROGNAME, LOG_PID, LOG_SYSLOG);
45 syslog(LOG_INFO, "(err) %s", buffer);
46 closelog();
47
48#ifdef DEBUG
49 fprintf(stderr, "(err) %s\n", buffer);
50#endif
51
52}
diff --git a/noncore/net/wellenreiter/daemon/source/log.hh b/noncore/net/wellenreiter/daemon/source/log.hh
new file mode 100644
index 0000000..bdea7e4
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/log.hh
@@ -0,0 +1,14 @@
1/* $Id$ */
2
3#ifndef LOG_HH
4#define LOG_HH
5
6#include <stdio.h>
7#include <syslog.h>
8#include <stdarg.h>
9#include <string.h>
10
11void log_info(const char *, ...);
12void log_err(const char *, ...);
13
14#endif /* LOG_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.cc b/noncore/net/wellenreiter/daemon/source/sendgui.cc
new file mode 100644
index 0000000..48ad5b8
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/sendgui.cc
@@ -0,0 +1,75 @@
1/*
2 * Send string to GUI
3 *
4 * $Id$
5 */
6
7#include "config.hh"
8#include "sendgui.hh"
9#include "log.hh"
10
11/* Simple dummy for alarm timer */
12static void alarmdummy(int signo)
13{
14 alarm (0);
15}
16
17/* Connect to given IP on given port */
18int connect_server(int *sock, unsigned int ipaddr, int port)
19{
20 struct sockaddr_in saddr;
21 int retval=0;
22
23 *sock = socket (PF_INET, SOCK_STREAM, 0);
24 saddr.sin_family = PF_INET;
25 saddr.sin_port = htons (port);
26 saddr.sin_addr.s_addr = ipaddr;
27
28 signal (SIGALRM, alarmdummy);
29 siginterrupt (SIGALRM, 1);
30
31 alarm(5);
32 retval=connect (*sock, (struct sockaddr *) &saddr, sizeof (saddr));
33 alarm(0);
34
35 if(retval < 0)
36 {
37 close (*sock);
38 return 0;
39 }
40
41 return 1;
42}
43
44/* Send a string to the GUI */
45int sendgui(const char *string, ...)
46{
47 int sock=0;
48 char buffer[4096];
49 va_list ap;
50
51 /* Generate string */
52 memset(buffer, 0, sizeof(buffer));
53 va_start(ap, string);
54 vsnprintf(buffer, sizeof(buffer)-1, string, ap);
55 va_end(ap);
56
57 if(!connect_server(&sock, inet_addr(GUIADDR), GUIPORT))
58 {
59 log_err("Connect to GUI at '%s' failed: %s", GUIADDR, strerror(errno));
60 return 0;
61 }
62
63 if(write(sock, buffer, sizeof(buffer)) < 0)
64 {
65 log_err("Cannot write to socket: %s", strerror(errno));
66 close(sock);
67 return 0;
68 }
69
70 if(close(sock) < 0)
71 log_err("Cannot close socket: %s", strerror(errno));
72
73 return 1;
74}
75
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.hh b/noncore/net/wellenreiter/daemon/source/sendgui.hh
new file mode 100644
index 0000000..e083704
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/sendgui.hh
@@ -0,0 +1,20 @@
1/* $Id$ */
2
3#ifndef SENDGUI_HH
4#define SENDGUI_HH
5
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <arpa/inet.h>
10#include <signal.h>
11#include <errno.h>
12#include <string.h>
13#include <stdio.h>
14#include <unistd.h>
15#include <stdlib.h>
16
17int connect_server(int *, unsigned int, int);
18int sendgui(const char *string, ...);
19
20#endif /* SENDGUI_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.c b/noncore/net/wellenreiter/daemon/source/sniffer.cc
index 31a5d13..c837505 100644
--- a/noncore/net/wellenreiter/daemon/source/sniffer.c
+++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc
@@ -1,166 +1,158 @@
1/* Its just a simple rfmon mode sniffer 1/*
2 i hope my C is at last a bit better then in my 2 * rfmon mode sniffer
3 early days :-). 3 * This works only with cisco wireless cards with an rfmon
4 This works only with cisco wireless cards with an rfmon 4 * able driver and not with wifi stuff.
5 able driver and not with wifi stuff. 5 *
6 Btw. did i mention that i hate C? 6 * $Id$
7 7 */
8 To compile use: 8
9 gcc sniffer.c -o wlan-sniffer -lpcap 9#include "config.hh"
10 10#include "sniffer.hh"
11*/ 11#include "ieee802_11.hh"
12#include "sniffer.h" 12#include "extract.hh"
13 13
14int main(int argc, char **argv) 14int sniffer(void)
15{ 15 {
16 int ret; /* return code */ 16 if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0)
17 ret = card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG); 17 return 0;
18 if (ret == -1)
19 {
20 exit(-1);
21 }
22 start_sniffing (SNIFFER_DEVICE); 18 start_sniffing (SNIFFER_DEVICE);
23 19
24 return 0; 20 return 1;
25} 21}
26 22
27int card_into_monitormode (char * device, int cardtype) 23int card_into_monitormode (char *device, int cardtype)
28{ 24{
29 int ret = -1; 25
30 int datalink; /* used for getting the pcap datalink type */ 26 int datalink; /* used for getting the pcap datalink type */
31 char CiscoRFMON[35] = "/proc/driver/aironet/"; 27 char CiscoRFMON[35] = "/proc/driver/aironet/";
32 FILE *CISCO_CONFIG_FILE; 28 FILE *CISCO_CONFIG_FILE;
33 char errbuf[PCAP_ERRBUF_SIZE]; 29 char errbuf[PCAP_ERRBUF_SIZE];
34 pcap_t *handle; 30 pcap_t *handle;
35 31
36 /* Checks if we have a device to sniff on */ 32 /* Checks if we have a device to sniff on */
37 if(device == NULL) 33 if(device == NULL)
38 { 34 {
39 printf ("Fatal error i did not have any interfaces to sniff on\n"); 35 printf ("Fatal error i did not have any interfaces to sniff on\n");
40 exit(1); 36 return 0;
41 } 37 }
42 38
43 /* Setting the prmiscous and up flag to the interface */ 39 /* Setting the prmiscous and up flag to the interface */
44 if (card_set_promisc_up (device) == 0) 40 if (card_set_promisc_up (device) == 0)
45 { 41 {
46 printf ("Interface flags correctly set using ifconfig\n"); 42 printf ("Interface flags correctly set using ifconfig\n");
47 } 43 }
48 44
49 /* Check the cardtype and executes the commands to go into monitor mode */ 45 /* Check the cardtype and executes the commands to go into monitor mode */
50 if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ 46 if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */
51 { 47 {
52 /* bring the sniffer into rfmon mode */ 48 /* bring the sniffer into rfmon mode */
53 snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); 49 snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device);
54 CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); 50 CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w");
55 fputs ("Mode: r",CISCO_CONFIG_FILE); 51 fputs ("Mode: r",CISCO_CONFIG_FILE);
56 fputs ("Mode: y",CISCO_CONFIG_FILE); 52 fputs ("Mode: y",CISCO_CONFIG_FILE);
57 fputs ("XmitPower: 1",CISCO_CONFIG_FILE); 53 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
58 fclose(CISCO_CONFIG_FILE); 54 fclose(CISCO_CONFIG_FILE);
59 } 55 }
60 else if (cardtype == CARD_TYPE_NG) 56 else if (cardtype == CARD_TYPE_NG)
61 { 57 {
62 char wlanngcmd[62]; 58 char wlanngcmd[62];
63 snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); 59 snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device);
64 if (ret = (system (wlanngcmd)) != 0) 60 if (system (wlanngcmd) != 0)
65 { 61 {
66 printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); 62 printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device);
67 exit(1); 63 return 0;
68 } 64 }
69 } 65 }
70 else if (cardtype == CARD_TYPE_HOSTAP) 66 else if (cardtype == CARD_TYPE_HOSTAP)
71 { 67 {
72 printf ("Got a host-ap card, nothing is implemented now\n"); 68 printf ("Got a host-ap card, nothing is implemented now\n");
73 } 69 }
74 70
75 71
76 /* Check the interface if it is in the correct raw mode */ 72 /* Check the interface if it is in the correct raw mode */
77 handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); 73 handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf);
78 74
79 /* getting the datalink type */ 75 /* getting the datalink type */
80 datalink = pcap_datalink(handle); 76 datalink = pcap_datalink(handle);
81 77
82 if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ 78 if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
83 { 79 {
84 printf ("Your successfully listen on %s in 802.11 raw mode\n",device); 80 printf ("Your successfully listen on %s in 802.11 raw mode\n",device);
85 pcap_close(handle); 81 pcap_close(handle);
86 return (0); 82 return 0;
87 83
88 } 84 }
89 else 85 else
90 { 86 {
91 printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); 87 printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device);
92 pcap_close(handle); 88 pcap_close(handle);
93 exit(1); 89 return 0;
94 } 90 }
95} 91}
96 92
97int card_set_promisc_up (char * device) 93int card_set_promisc_up (char * device)
98{ 94{
99 int ret; 95 int ret;
100 char ifconfigcmd[32]; 96 char ifconfigcmd[32];
101 snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); 97 snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device);
102 ret = system (ifconfigcmd); 98 ret = system (ifconfigcmd);
103 if (ret > 0) 99 if (ret > 0)
104 { 100 {
105 printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); 101 printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd);
106 exit(1); 102 return 0;
107 } 103 }
108 return(0); 104 return 1;
109} 105}
110 106
111int start_sniffing (char * device) 107int start_sniffing (char * device)
112{ 108{
113 int ret; /* return code */ 109
114 pcap_t *handletopcap; 110 pcap_t *handletopcap;
115 char errbuf[PCAP_ERRBUF_SIZE]; 111 char errbuf[PCAP_ERRBUF_SIZE];
116 struct pcap_pkthdr header; /* The header that pcap gives us */
117 const u_char *packet; /* The actual packet */
118 112
119 /* opening the pcap for sniffing */ 113 /* opening the pcap for sniffing */
120 handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); 114 handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf);
121 115
122 /* Next few lines a taken out of kismet */ 116 /* Next few lines a taken out of kismet */
123 #ifdef HAVE_PCAP_NONBLOCK 117 #ifdef HAVE_PCAP_NONBLOCK
124 pcap_setnonblock(handletopcap, 1, errstr); 118 pcap_setnonblock(handletopcap, 1, errstr);
125 #endif 119 #endif
126 120
127 /*start scanning */ 121 /*start scanning */
128 pcap_loop(handletopcap,-1,process_packets,NULL); 122 pcap_loop(handletopcap,-1,process_packets,NULL);
129 123
130 printf("\nDone processing packets... wheew!\n"); 124 printf("\nDone processing packets... wheew!\n");
131 return 0; 125 return 1;
132} 126}
133 127
134void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) 128void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet)
135{ 129{
136 u_int caplen = pkthdr->caplen; 130 u_int caplen = pkthdr->caplen;
137 u_int length = pkthdr->len; 131 u_int length = pkthdr->len;
138 u_int16_t fc; 132 u_int16_t fc;
139 u_int HEADER_LENGTH; 133 u_int HEADER_LENGTH;
140 u_short extracted_ethertype; 134
141 int snapend;
142 int ret;
143 /* pinfo holds all interresting information for us */ 135 /* pinfo holds all interresting information for us */
144 struct packetinfo pinfo; 136 struct packetinfo pinfo;
145 struct packetinfo *pinfoptr; 137 struct packetinfo *pinfoptr;
146 pinfoptr=&pinfo; 138 pinfoptr=&pinfo;
147 139
148 pinfoptr->isvalid = 0; 140 pinfoptr->isvalid = 0;
149 pinfoptr->pktlen = pkthdr->len; 141 pinfoptr->pktlen = pkthdr->len;
150 if (caplen < IEEE802_11_FC_LEN) 142 if (caplen < IEEE802_11_FC_LEN)
151 { 143 {
152 /* This is a garbage packet, because is does not long enough 144 /* This is a garbage packet, because is does not long enough
153 to hold a 802.11b header */ 145 to hold a 802.11b header */
154 pinfoptr->isvalid = 0; 146 pinfoptr->isvalid = 0;
155 return; 147 return;
156 } 148 }
157 149
158 /* Gets the framecontrol bits (2bytes long) */ 150 /* Gets the framecontrol bits (2bytes long) */
159 fc = EXTRACT_LE_16BITS(packet); 151 fc = EXTRACT_LE_16BITS(packet);
160 152
161 HEADER_LENGTH = GetHeaderLength(fc); 153 HEADER_LENGTH = GetHeaderLength(fc);
162 154
163 if (caplen < HEADER_LENGTH) 155 if (caplen < HEADER_LENGTH)
164 { 156 {
165 /* This is a garbage packet, because it is not long enough 157 /* This is a garbage packet, because it is not long enough
166 to hold a correct header of its type */ 158 to hold a correct header of its type */
@@ -242,166 +234,158 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
242 printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc)); 234 printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc));
243 break; 235 break;
244 } /* End of switch over different mgt frame types */ 236 } /* End of switch over different mgt frame types */
245 237
246 break; 238 break;
247 case T_CTRL: 239 case T_CTRL:
248 //decode_control_frames(fc, packet); 240 //decode_control_frames(fc, packet);
249 printf ("Its a control frame"); 241 printf ("Its a control frame");
250 break; 242 break;
251 case T_DATA: 243 case T_DATA:
252 //decode_data_frames(fc, packet); 244 //decode_data_frames(fc, packet);
253 printf ("Its a date frame"); 245 printf ("Its a date frame");
254 break; 246 break;
255 default: 247 default:
256 printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc)); 248 printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc));
257 break; 249 break;
258 } 250 }
259} 251}
260 252
261 253
262/* This decodes the 802.11b frame header out of the 802.11b packet 254/* This decodes the 802.11b frame header out of the 802.11b packet
263 all the infos is placed into the packetinfo structure */ 255 all the infos is placed into the packetinfo structure */
264int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) 256int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo)
265{ 257{
266 char * ret;
267 char testme[16];
268 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; 258 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p;
269 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); 259 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc);
270 260
271 /* Get the sender, bssid and dest mac address */ 261 /* Get the sender, bssid and dest mac address */
272 etheraddr_string(mgthdr->bssid,ppinfo->bssid); 262 etheraddr_string(mgthdr->bssid,ppinfo->bssid);
273 etheraddr_string(mgthdr->da,ppinfo->desthwaddr); 263 etheraddr_string(mgthdr->da,ppinfo->desthwaddr);
274 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); 264 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr);
275 ppinfo->fc_wep = FC_WEP(mgthdr->fc); 265 ppinfo->fc_wep = FC_WEP(mgthdr->fc);
276 return(0); 266 return 0;
277} 267}
278 268
279 269
280void etheraddr_string(register const u_char *ep,char * text) 270void etheraddr_string(register const u_char *ep,char * text)
281{ 271{
282 static char hex[] = "0123456789abcdef"; 272 static char hex[] = "0123456789abcdef";
283 register u_int i, j; 273 register u_int i, j;
284 register char *cp; 274 register char *cp;
285 char buf[sizeof("00:00:00:00:00:00")]; 275 char buf[sizeof("00:00:00:00:00:00")];
286 cp = buf; 276 cp = buf;
287 if ((j = *ep >> 4) != 0) 277 if ((j = *ep >> 4) != 0)
288 *cp++ = hex[j]; 278 *cp++ = hex[j];
289 *cp++ = hex[*ep++ & 0xf]; 279 *cp++ = hex[*ep++ & 0xf];
290 for (i = 5; (int)--i >= 0;) { 280 for (i = 5; (int)--i >= 0;) {
291 *cp++ = ':'; 281 *cp++ = ':';
292 if ((j = *ep >> 4) != 0) 282 if ((j = *ep >> 4) != 0)
293 *cp++ = hex[j]; 283 *cp++ = hex[j];
294 *cp++ = hex[*ep++ & 0xf]; 284 *cp++ = hex[*ep++ & 0xf];
295 } 285 }
296 *cp = '\0'; 286 *cp = '\0';
297 strcpy(text,buf); 287 strcpy(text,buf);
298 return;
299} 288}
300 289
301int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) 290int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
302{ 291{
303 struct mgmt_body_t pbody; 292 struct mgmt_body_t pbody;
304 int offset = 0; 293 int offset = 0;
305 294
306 /* Get the static informations out of the packet */ 295 /* Get the static informations out of the packet */
307 memset(&pbody, 0, sizeof(pbody)); 296 memset(&pbody, 0, sizeof(pbody));
308 memcpy(&pbody.timestamp, p, 8); 297 memcpy(&pbody.timestamp, p, 8);
309 offset += 8; 298 offset += 8;
310 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 299 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
311 offset += 2; 300 offset += 2;
312 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 301 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
313 offset += 2; 302 offset += 2;
314 303
315 /* Gets the different flags out of the capabilities */ 304 /* Gets the different flags out of the capabilities */
316 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); 305 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info);
317 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); 306 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info);
318 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); 307 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info);
319 308
320 /* Gets the tagged elements out of the packets */ 309 /* Gets the tagged elements out of the packets */
321 while (offset + 1 < ppinfo->pktlen) 310 while (offset + 1 < ppinfo->pktlen)
322 { 311 {
323 switch (*(p + offset)) 312 switch (*(p + offset))
324 { 313 {
325 case E_SSID: 314 case E_SSID:
326 memcpy(&(pbody.ssid),p+offset,2); offset += 2; 315 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
327 if (pbody.ssid.length > 0) 316 if (pbody.ssid.length > 0)
328 { 317 {
329 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; 318 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length;
330 pbody.ssid.ssid[pbody.ssid.length]='\0'; 319 pbody.ssid.ssid[pbody.ssid.length]='\0';
331 if (strcmp(pbody.ssid.ssid,"")==0) 320 if (strcmp((char *)pbody.ssid.ssid,"")==0)
332 { 321 {
333 ppinfo->ssid = NONBROADCASTING; 322 ppinfo->ssid = NONBROADCASTING;
334 } 323 }
335 else 324 else
336 { 325 {
337 ppinfo->ssid = pbody.ssid.ssid; 326 ppinfo->ssid = (char *)pbody.ssid.ssid;
338 } 327 }
339 ppinfo->ssid_len = pbody.ssid.length; 328 ppinfo->ssid_len = pbody.ssid.length;
340 } 329 }
341 break; 330 break;
342 case E_CHALLENGE: 331 case E_CHALLENGE:
343 memcpy(&(pbody.challenge),p+offset,2); offset += 2; 332 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
344 if (pbody.challenge.length > 0) 333 if (pbody.challenge.length > 0)
345 { 334 {
346 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; 335 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length;
347 pbody.challenge.text[pbody.challenge.length]='\0'; 336 pbody.challenge.text[pbody.challenge.length]='\0';
348 } 337 }
349 break; 338 break;
350 case E_RATES: 339 case E_RATES:
351 memcpy(&(pbody.rates),p+offset,2); offset += 2; 340 memcpy(&(pbody.rates),p+offset,2); offset += 2;
352 if (pbody.rates.length > 0) { 341 if (pbody.rates.length > 0) {
353 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; 342 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length;
354 } 343 }
355 break; 344 break;
356 case E_DS: 345 case E_DS:
357 memcpy(&(pbody.ds),p+offset,3); offset +=3; 346 memcpy(&(pbody.ds),p+offset,3); offset +=3;
358 ppinfo->channel = pbody.ds.channel; 347 ppinfo->channel = pbody.ds.channel;
359 break; 348 break;
360 case E_CF: 349 case E_CF:
361 memcpy(&(pbody.cf),p+offset,8); offset +=8; 350 memcpy(&(pbody.cf),p+offset,8); offset +=8;
362 break; 351 break;
363 case E_TIM: 352 case E_TIM:
364 memcpy(&(pbody.tim),p+offset,2); offset +=2; 353 memcpy(&(pbody.tim),p+offset,2); offset +=2;
365 memcpy(&(pbody.tim.count),p+offset,3); offset +=3; 354 memcpy(&(pbody.tim.count),p+offset,3); offset +=3;
366 if ((pbody.tim.length -3) > 0) 355 if ((pbody.tim.length -3) > 0)
367 { 356 {
368 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); 357 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
369 offset += pbody.tim.length -3; 358 offset += pbody.tim.length -3;
370 } 359 }
371 break; 360 break;
372 default: 361 default:
373#if 0 362
374 printf("(1) unhandled element_id (%d) ", *(p+offset) );
375#endif
376 offset+= *(p+offset+1) + 2; 363 offset+= *(p+offset+1) + 2;
377 break; 364 break;
378 } /* end of switch*/ 365 } /* end of switch*/
379 } /* end of for loop */ 366 } /* end of for loop */
380 return(0); 367 return 1;
381
382
383
384 368
385} /* End of handle_beacon */ 369} /* End of handle_beacon */
386 370
387 371
388static int GetHeaderLength(u_int16_t fc) 372static int GetHeaderLength(u_int16_t fc)
389{ 373{
390 int iLength=0; 374 int iLength=0;
391 375
392 switch (FC_TYPE(fc)) { 376 switch (FC_TYPE(fc)) {
393 case T_MGMT: 377 case T_MGMT:
394 iLength = MGMT_HEADER_LEN; 378 iLength = MGMT_HEADER_LEN;
395 break; 379 break;
396 case T_CTRL: 380 case T_CTRL:
397 switch (FC_SUBTYPE(fc)) { 381 switch (FC_SUBTYPE(fc)) {
398 case CTRL_PS_POLL: 382 case CTRL_PS_POLL:
399 iLength = CTRL_PS_POLL_LEN; 383 iLength = CTRL_PS_POLL_LEN;
400 break; 384 break;
401 case CTRL_RTS: 385 case CTRL_RTS:
402 iLength = CTRL_RTS_LEN; 386 iLength = CTRL_RTS_LEN;
403 break; 387 break;
404 case CTRL_CTS: 388 case CTRL_CTS:
405 iLength = CTRL_CTS_LEN; 389 iLength = CTRL_CTS_LEN;
406 break; 390 break;
407 case CTRL_ACK: 391 case CTRL_ACK:
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.h b/noncore/net/wellenreiter/daemon/source/sniffer.hh
index b880b68..7f45be6 100644
--- a/noncore/net/wellenreiter/daemon/source/sniffer.h
+++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh
@@ -1,102 +1,83 @@
1// Wellenreiter-sniffer-code header file 1/* $Id$ */
2
3#ifndef SNIFFER_HH
4#define SNIFFER_HH
2 5
3#include <string.h> 6#include <string.h>
4#include <stdio.h> 7#include <stdio.h>
5#include <stdlib.h> 8#include <stdlib.h>
6#include <pcap.h> 9#include <pcap.h>
7#include <errno.h> 10#include <errno.h>
8#include <sys/socket.h> 11#include <sys/socket.h>
9#include <netinet/in.h> 12#include <netinet/in.h>
10#include <arpa/inet.h> 13#include <arpa/inet.h>
11#include <net/bpf.h> 14#include <net/bpf.h>
12#include "ieee802_11.h"
13#include "extract.h"
14 15
15#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 16#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
16 #define CARD_TYPE_CISCO1 17 #define CARD_TYPE_CISCO1
17 #define CARD_TYPE_NG2 18 #define CARD_TYPE_NG2
18 #define CARD_TYPE_HOSTAP3 19 #define CARD_TYPE_HOSTAP3
19 20
20#define NONBROADCASTING "non-broadcasting" 21#define NONBROADCASTING "non-broadcasting"
21 22
22/* only for now, until we have the daemon running */ 23/* only for now, until we have the daemon running */
23/*the config file should provide these information */ 24/*the config file should provide these information */
24 #define SNIFFER_DEVICE "wlan0" 25 #define SNIFFER_DEVICE "wlan0"
25#define CARD_TYPE CARD_TYPE_CISCO 26#define CARD_TYPE CARD_TYPE_CISCO
26 #define SBIN_PATH"/sbin/ifconfig %s promisc up" 27 #define SBIN_PATH"/sbin/ifconfig %s promisc up"
27#define WLANCTL_PATH "/sbin/wlanctl-ng" 28#define WLANCTL_PATH "/sbin/wlanctl-ng"
28 29
29/* holds all the interresting data */ 30/* holds all the interresting data */
30struct packetinfo 31struct packetinfo
31{ 32{
32 int isvalid; 33 int isvalid;
33 int pktlen; 34 int pktlen;
34 int fctype; 35 int fctype;
35 int fcsubtype; 36 int fcsubtype;
36 int fc_wep; 37 int fc_wep;
37 int cap_WEP; 38 int cap_WEP;
38 int cap_IBSS; 39 int cap_IBSS;
39 int cap_ESS; 40 int cap_ESS;
40 int channel; 41 int channel;
41 char bssid[sizeof("00:00:00:00:00:00")]; 42 char bssid[sizeof("00:00:00:00:00:00")];
42 char desthwaddr[sizeof("00:00:00:00:00:00")]; 43 char desthwaddr[sizeof("00:00:00:00:00:00")];
43 char sndhwaddr[sizeof("00:00:00:00:00:00")]; 44 char sndhwaddr[sizeof("00:00:00:00:00:00")];
44 char *ssid; 45 char *ssid;
45 int ssid_len; 46 int ssid_len;
46}; 47};
47 48
48 49
49/* Prototypes */ 50/* Prototypes */
50int card_into_monitormode (char * device, int cardtype);
51 51
52int sniffer(void);
53int card_into_monitormode (char * device, int cardtype);
52int card_set_promisc_up (char * device); 54int card_set_promisc_up (char * device);
53
54int start_sniffing (char * device); 55int start_sniffing (char * device);
55
56void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); 56void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet);
57
58int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); 57int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo);
59
60void etheraddr_string(register const u_char *ep,char * text); 58void etheraddr_string(register const u_char *ep,char * text);
61
62int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); 59int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo);
63 60
64static int GetHeaderLength(u_int16_t fc); 61static int GetHeaderLength(u_int16_t fc);
65 62
66static const char *subtype_text[]={
67 "Assoc Request",
68 "Assoc Response",
69 "ReAssoc Request",
70 "ReAssoc Response",
71 "Probe Request",
72 "Probe Response",
73 "RESERVED",
74 "RESERVED",
75 "Beacon",
76 "ATIM",
77 "Disassociation",
78 "Authentication",
79 "DeAuthentication",
80 "RESERVED",
81 "RESERVED"
82};
83
84/* 63/*
85 * True if "l" bytes of "var" were captured. 64 * True if "l" bytes of "var" were captured.
86 * 65 *
87 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 66 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
88 * that "snapend - (l)" underflows. 67 * that "snapend - (l)" underflows.
89 * 68 *
90 * The check is for <= rather than < because "l" might be 0. 69 * The check is for <= rather than < because "l" might be 0.
91 */ 70 */
92#define TTEST2(var, l) (snapend - (l) <= snapend && \ 71#define TTEST2(var, l) (snapend - (l) <= snapend && \
93 (const u_char *)&(var) <= snapend - (l)) 72 (const u_char *)&(var) <= snapend - (l))
94 73
95/* True if "var" was captured */ 74/* True if "var" was captured */
96#define TTEST(var) TTEST2(var, sizeof(var)) 75#define TTEST(var) TTEST2(var, sizeof(var))
97 76
98/* Bail if "l" bytes of "var" were not captured */ 77/* Bail if "l" bytes of "var" were not captured */
99#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 78#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc
100 79
101/* Bail if "var" was not captured */ 80/* Bail if "var" was not captured */
102#define TCHECK(var) TCHECK2(var, sizeof(var)) 81#define TCHECK(var) TCHECK2(var, sizeof(var))
82
83#endif /* SNIFFER_HH */