summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-16 17:59:21 (UTC)
committer mjm <mjm>2002-12-16 17:59:21 (UTC)
commit1a981d3a1d8ef7860d673bce009b7253d7e279d7 (patch) (unidiff)
tree0a9e31d9cee51110dfe67b8c0ef1f2c8d0a27241
parente6255e52c1ec8988f3a1490827b92874459d6ede (diff)
downloadopie-1a981d3a1d8ef7860d673bce009b7253d7e279d7.zip
opie-1a981d3a1d8ef7860d673bce009b7253d7e279d7.tar.gz
opie-1a981d3a1d8ef7860d673bce009b7253d7e279d7.tar.bz2
foobar
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/config.hh2
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc35
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.hh2
3 files changed, 31 insertions, 8 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/config.hh b/noncore/net/wellenreiter/daemon/source/config.hh
index 42c56da..cac9565 100644
--- a/noncore/net/wellenreiter/daemon/source/config.hh
+++ b/noncore/net/wellenreiter/daemon/source/config.hh
@@ -1,30 +1,28 @@
1/* 1/*
2 * 2 *
3 * Global configuration for wellenreiter 3 * Global configuration for wellenreiter
4 * 4 *
5 * $Id$ 5 * $Id$
6 * 6 *
7 * Written by Martin J. Muench <mjm@codito.de> 7 * Written by Martin J. Muench <mjm@codito.de>
8 * 8 *
9 */ 9 */
10 10
11#ifndef CONFIG_HH 11#ifndef CONFIG_HH
12#define CONFIG_HH 12#define CONFIG_HH
13 13
14#define PROGNAME "wellenreiter" /* Name of program (for syslog et.al.) */ 14#define PROGNAME "wellenreiter" /* Name of program (for syslog et.al.) */
15#define VERSION "0.2" /* Version of wellenreiter */ 15#define VERSION "0.2" /* Version of wellenreiter */
16 16
17#define DAEMONADDR "127.0.0.1" 17#define DAEMONADDR "127.0.0.1"
18#define DAEMONPORT 37772 /* Port of Daemon */ 18#define DAEMONPORT 37772 /* Port of Daemon */
19 19
20#define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */ 20#define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */
21#define GUIPORT 37773 /* Port of GUI, " " */ 21#define GUIPORT 37773 /* Port of GUI, " " */
22 22
23
24/* Temporary cardmode stuff, will hopefully removed soon */ 23/* Temporary cardmode stuff, will hopefully removed soon */
25#define CARD_TYPE_CISCO 1 24#define CARD_TYPE_CISCO 1
26#define CARD_TYPE_NG 2 25#define CARD_TYPE_NG 2
27#define CARD_TYPE_HOSTAP 3 26#define CARD_TYPE_HOSTAP 3
28#define SNIFFER_DEVICE "wlan0"
29 27
30#endif /* CONFIG_HH */ 28#endif /* CONFIG_HH */
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
index cc72377..54f308a 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.cc
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -1,81 +1,94 @@
1/* 1/*
2 * Startup functions of wellenreiter 2 * Startup functions of wellenreiter
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "config.hh" 7#include "config.hh"
8#include "daemon.hh" 8#include "daemon.hh"
9 9
10/* Main function of wellenreiterd */ 10/* Main function of wellenreiterd */
11int main(int argc, char **argv) 11int main(int argc, char **argv)
12{ 12{
13 int sock, maxfd, retval; 13 int sock, maxfd, retval, card_type;
14 char buffer[128]; 14 char buffer[128], sniffer_device[5];
15 struct pcap_pkthdr header; 15 struct pcap_pkthdr header;
16 pcap_t *handletopcap; 16 pcap_t *handletopcap;
17 const unsigned char *packet; 17 const unsigned char *packet;
18 18
19 fd_set rset; 19 fd_set rset;
20 20
21 fprintf(stderr, "wellenreiterd %s\n\n", VERSION); 21 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
22 fprintf(stderr, "(c) 2002 by M-M-M\n\n");
22 23
23 if(!card_into_monitormode(&handletopcap, SNIFFER_DEVICE, CARD_TYPE)) 24 if(argc < 3)
25 usage();
26
27 /* Set sniffer device */
28 memset(sniffer_device, 0, sizeof(sniffer_device));
29 strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1);
30
31 /* Set card type */
32 card_type = atoi(argv[2]);
33 if(card_type < 1 || card_type > 3)
34 usage();
35
36 if(!card_into_monitormode(&handletopcap, sniffer_device, card_type))
24 { 37 {
25 wl_logerr("Cannot set card into mon mode, aborting"); 38 wl_logerr("Cannot set card into mon mode, aborting");
26 exit(-1); 39 exit(-1);
27 } 40 }
28 wl_loginfo("Set card into monitor mode"); 41 wl_loginfo("Set card into monitor mode");
29 42
30 /////// following line will be moved to lib as soon as possible //////////// 43 /////// following line will be moved to lib as soon as possible ////////////
31 if((handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 0, NULL)) == NULL) 44 if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL)
32 { 45 {
33 wl_logerr("pcap_open_live() failed: %s", strerror(errno)); 46 wl_logerr("pcap_open_live() failed: %s", strerror(errno));
34 exit(-1); 47 exit(-1);
35 } 48 }
36 49
37#ifdef HAVE_PCAP_NONBLOCK 50#ifdef HAVE_PCAP_NONBLOCK
38 pcap_setnonblock(handletopcap, 1, NULL); 51 pcap_setnonblock(handletopcap, 1, NULL);
39#endif 52#endif
40 53
41 /* getting the datalink type */ 54 /* getting the datalink type */
42 retval = pcap_datalink(handletopcap); 55 retval = pcap_datalink(handletopcap);
43 if (retval != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ 56 if (retval != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
44 { 57 {
45 wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", SNIFFER_DEVICE); 58 wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", sniffer_device);
46 pcap_close(handletopcap); 59 pcap_close(handletopcap);
47 return 0; 60 return 0;
48 } 61 }
49 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", SNIFFER_DEVICE); 62 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", sniffer_device);
50 //////////////////////////////////////// 63 ////////////////////////////////////////
51 64
52 /* Setup socket for incoming commands */ 65 /* Setup socket for incoming commands */
53 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) 66 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0)
54 { 67 {
55 wl_logerr("Cannot setup socket"); 68 wl_logerr("Cannot setup socket");
56 exit(-1); 69 exit(-1);
57 } 70 }
58 wl_loginfo("Set up socket '%d' for GUI communication", sock); 71 wl_loginfo("Set up socket '%d' for GUI communication", sock);
59 72
60 FD_ZERO(&rset); 73 FD_ZERO(&rset);
61 74
62 /* Start main loop */ 75 /* Start main loop */
63 wl_loginfo("Starting main loop"); 76 wl_loginfo("Starting main loop");
64 while(1) 77 while(1)
65 { 78 {
66 79
67 FD_SET(sock, &rset); 80 FD_SET(sock, &rset);
68 FD_SET(pcap_fileno(handletopcap), &rset); 81 FD_SET(pcap_fileno(handletopcap), &rset);
69 maxfd=sock + pcap_fileno(handletopcap) + 1; 82 maxfd=sock + pcap_fileno(handletopcap) + 1;
70 83
71 if(select(maxfd, &rset, NULL, NULL, NULL) < 0) 84 if(select(maxfd, &rset, NULL, NULL, NULL) < 0)
72 { 85 {
73 wl_logerr("Error calling select: %s", strerror(errno)); 86 wl_logerr("Error calling select: %s", strerror(errno));
74 break; 87 break;
75 } 88 }
76 89
77 /* Got data on local socket from GUI */ 90 /* Got data on local socket from GUI */
78 if(FD_ISSET(sock, &rset)) 91 if(FD_ISSET(sock, &rset))
79 { 92 {
80 /* Receive data from socket */ 93 /* Receive data from socket */
81 if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0) 94 if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0)
@@ -88,32 +101,42 @@ int main(int argc, char **argv)
88 /* check type of packet and start function according to it */ 101 /* check type of packet and start function according to it */
89 switch(retval) 102 switch(retval)
90 { 103 {
91 case 98: 104 case 98:
92 wl_loginfo("Received STARTSNIFF command"); 105 wl_loginfo("Received STARTSNIFF command");
93 break; 106 break;
94 case 99: 107 case 99:
95 wl_loginfo("Received STOPSNIFF command"); 108 wl_loginfo("Received STOPSNIFF command");
96 break; 109 break;
97 default: 110 default:
98 wl_logerr("Received unknown command: %d", retval); 111 wl_logerr("Received unknown command: %d", retval);
99 break; 112 break;
100 } 113 }
101 } 114 }
102 } /* FD_ISSET */ 115 } /* FD_ISSET */
103 116
104 /* Check pcap lib for packets */ 117 /* Check pcap lib for packets */
105 if(FD_ISSET(pcap_fileno(handletopcap), &rset)) 118 if(FD_ISSET(pcap_fileno(handletopcap), &rset))
106 { 119 {
107 120
108 /* Grab one single packet */ 121 /* Grab one single packet */
109 packet = pcap_next(handletopcap, &header); 122 packet = pcap_next(handletopcap, &header);
110 123
111 /* process the packet */ 124 /* process the packet */
112 process_packets(&header,*&packet, GUIADDR, GUIPORT); 125 process_packets(&header,*&packet, GUIADDR, GUIPORT);
113 } 126 }
114 127
115 } /* while(1) */ 128 } /* while(1) */
116 129
117 close(sock); 130 close(sock);
118 exit(0); 131 exit(0);
119} 132}
133
134void usage(void)
135{
136 fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \
137 "\t<device> = Wirelessdevice (e.g. wlan0)\n" \
138 "\t<cardtype> = Cardtype:\t Cisco\t= 1\n" \
139 "\t\t\t\tNG\t= 2\n" \
140 "\t\t\t\tHOSTAP\t= 3\n");
141 exit(-1);
142}
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh
index 09acf11..8d03b97 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.hh
+++ b/noncore/net/wellenreiter/daemon/source/daemon.hh
@@ -1,22 +1,24 @@
1/* $Id$ */ 1/* $Id$ */
2 2
3#ifndef DAEMON_HH 3#ifndef DAEMON_HH
4#define DAEMON_HH 4#define DAEMON_HH
5 5
6#include <stdio.h> 6#include <stdio.h>
7#include <string.h> 7#include <string.h>
8#include <sys/types.h> 8#include <sys/types.h>
9#include <sys/time.h> 9#include <sys/time.h>
10#include <sys/socket.h> 10#include <sys/socket.h>
11#include <netinet/in.h> 11#include <netinet/in.h>
12#include <arpa/inet.h> 12#include <arpa/inet.h>
13#include <unistd.h> 13#include <unistd.h>
14#include <errno.h> 14#include <errno.h>
15 15
16#include "../../libwellenreiter/source/sock.hh" 16#include "../../libwellenreiter/source/sock.hh"
17#include "../../libwellenreiter/source/log.hh" 17#include "../../libwellenreiter/source/log.hh"
18#include "../../libwellenreiter/source/proto.hh" 18#include "../../libwellenreiter/source/proto.hh"
19#include "../../libwellenreiter/source/cardmode.hh" 19#include "../../libwellenreiter/source/cardmode.hh"
20#include "../../libwellenreiter/source/sniff.hh" 20#include "../../libwellenreiter/source/sniff.hh"
21 21
22void usage(void);
23
22#endif /* DAEMON_HH */ 24#endif /* DAEMON_HH */