summaryrefslogtreecommitdiff
authormjm <mjm>2002-11-12 22:12:33 (UTC)
committer mjm <mjm>2002-11-12 22:12:33 (UTC)
commiteaecbed44924ece119c5b41db2828b4554f263d2 (patch) (unidiff)
treeb87dd3d049ea1768b20192f6c674f8684a41282c
parent15bc80dffd7a4c52985a742cb3a439da42692478 (diff)
downloadopie-eaecbed44924ece119c5b41db2828b4554f263d2.zip
opie-eaecbed44924ece119c5b41db2828b4554f263d2.tar.gz
opie-eaecbed44924ece119c5b41db2828b4554f263d2.tar.bz2
pre-alpha version, most things does not work yet.
todo: communication protocol with GUI and implementation of sniffer
Diffstat (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,6 +1,7 @@
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
@@ -14,18 +15,18 @@
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 | \
@@ -52,6 +53,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,7 +1,7 @@
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
@@ -18,12 +18,15 @@
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 */
@@ -240,6 +243,8 @@ struct ctrl_end_ack_t {
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,46 +1,42 @@
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");
@@ -58,16 +54,16 @@ int card_into_monitormode (char * device, int cardtype)
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 }
@@ -79,70 +75,66 @@ int card_into_monitormode (char * device, int cardtype)
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;
@@ -260,23 +252,21 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
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";
@@ -292,13 +282,12 @@ void etheraddr_string(register const u_char *ep,char * text)
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;
@@ -325,19 +314,19 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
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;
@@ -367,23 +356,18 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
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{
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,19 +1,20 @@
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
@@ -44,46 +45,24 @@ struct packetinfo
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 *
@@ -97,6 +76,8 @@ static const char *subtype_text[]={
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 */