author | mjm <mjm> | 2002-11-12 22:12:33 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-11-12 22:12:33 (UTC) |
commit | eaecbed44924ece119c5b41db2828b4554f263d2 (patch) (unidiff) | |
tree | b87dd3d049ea1768b20192f6c674f8684a41282c | |
parent | 15bc80dffd7a4c52985a742cb3a439da42692478 (diff) | |
download | opie-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
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 | |||
24 | clean 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 @@ | |||
1 | compile it using: | ||
2 | |||
3 | gcc -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 @@ | |||
1 | implement communication protocol | ||
2 | security analysis | ||
3 | implement sniffer (last step) | ||
4 | security analysis | ||
5 | code 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 */ | ||
14 | int 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,37 +1,38 @@ | |||
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))) |
@@ -46,12 +47,14 @@ | |||
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 | |||
12 | struct sockaddr_in saddr; | ||
13 | |||
14 | /* Setup UDP Socket for incoming commands */ | ||
15 | int 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 | |||
39 | int 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 | |||
13 | int commsock(int *); | ||
14 | int 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,35 +1,38 @@ | |||
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 |
@@ -234,12 +237,14 @@ struct 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 */ | ||
11 | void 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 */ | ||
33 | void 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 | |||
11 | void log_info(const char *, ...); | ||
12 | void 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 */ | ||
12 | static void alarmdummy(int signo) | ||
13 | { | ||
14 | alarm (0); | ||
15 | } | ||
16 | |||
17 | /* Connect to given IP on given port */ | ||
18 | int 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 */ | ||
45 | int 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 | |||
17 | int connect_server(int *, unsigned int, int); | ||
18 | int 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,154 +1,146 @@ | |||
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 | ||
14 | int main(int argc, char **argv) | 14 | int 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 | ||
27 | int card_into_monitormode (char * device, int cardtype) | 23 | int 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 | ||
97 | int card_set_promisc_up (char * device) | 93 | int 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 | ||
111 | int start_sniffing (char * device) | 107 | int 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 | ||
134 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 128 | void 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; |
@@ -254,57 +246,54 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch | |||
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 */ |
264 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 256 | int 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 | ||
280 | void etheraddr_string(register const u_char *ep,char * text) | 270 | void 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 | ||
301 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 290 | int 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); |
@@ -319,31 +308,31 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
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; |
@@ -361,35 +350,30 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
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 | ||
388 | static int GetHeaderLength(u_int16_t fc) | 372 | static 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; |
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,25 +1,26 @@ | |||
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 |
@@ -38,65 +39,45 @@ struct packetinfo | |||
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 */ |
50 | int card_into_monitormode (char * device, int cardtype); | ||
51 | 51 | ||
52 | int sniffer(void); | ||
53 | int card_into_monitormode (char * device, int cardtype); | ||
52 | int card_set_promisc_up (char * device); | 54 | int card_set_promisc_up (char * device); |
53 | |||
54 | int start_sniffing (char * device); | 55 | int start_sniffing (char * device); |
55 | |||
56 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); | 56 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); |
57 | |||
58 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 57 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
59 | |||
60 | void etheraddr_string(register const u_char *ep,char * text); | 58 | void etheraddr_string(register const u_char *ep,char * text); |
61 | |||
62 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 59 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
63 | 60 | ||
64 | static int GetHeaderLength(u_int16_t fc); | 61 | static int GetHeaderLength(u_int16_t fc); |
65 | 62 | ||
66 | static 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 */ | ||