author | mjm <mjm> | 2003-02-07 11:35:02 (UTC) |
---|---|---|
committer | mjm <mjm> | 2003-02-07 11:35:02 (UTC) |
commit | e92743832becd6dc8040e62e73c8ac3f7194f2d6 (patch) (unidiff) | |
tree | 16c10598f92097f5900278c780196a30a42ab023 | |
parent | 9bbfe155d26fe42ecb31744de0525a1f854b7ca5 (diff) | |
download | opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.zip opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.tar.gz opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.tar.bz2 |
inserted temporary channel switching via alarm()
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 51c2194..d6e8f6b 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,136 +1,157 @@ | |||
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 | // temporary solution, will be removed soon | ||
11 | #define MAXCHANNEL 13 | ||
12 | char sniffer_device[6]; | ||
13 | int channel=0; | ||
14 | int timedout=1; | ||
15 | |||
16 | static int chanswitch() | ||
17 | { | ||
18 | if(channel >= MAXCHANNEL) | ||
19 | channel=1 | ||
20 | card_set_channel(sniffer_device, channel, card_type); | ||
21 | timedout=0; | ||
22 | } | ||
23 | |||
10 | /* Main function of wellenreiterd */ | 24 | /* Main function of wellenreiterd */ |
11 | int main(int argc, char **argv) | 25 | int main(int argc, char **argv) |
12 | { | 26 | { |
13 | int sock, maxfd, retval, card_type; | 27 | int sock, maxfd, retval, card_type; |
14 | char buffer[WL_SOCKBUF], sniffer_device[6]; | 28 | char buffer[WL_SOCKBUF]; |
15 | struct pcap_pkthdr header; | 29 | struct pcap_pkthdr header; |
16 | struct sockaddr_in saddr; | 30 | struct sockaddr_in saddr; |
17 | pcap_t *handletopcap; | 31 | pcap_t *handletopcap; |
18 | const unsigned char *packet; | 32 | const unsigned char *packet; |
19 | 33 | ||
20 | fd_set rset; | 34 | fd_set rset; |
21 | 35 | ||
22 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 36 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
23 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | 37 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); |
24 | 38 | ||
25 | if(argc < 3) | 39 | if(argc < 3) |
26 | usage(); | 40 | usage(); |
27 | 41 | ||
42 | // removed soon, see above | ||
43 | SIGNAL(SIGALRM, chanswitch); | ||
44 | |||
28 | /* Set sniffer device */ | 45 | /* Set sniffer device */ |
29 | memset(sniffer_device, 0, sizeof(sniffer_device)); | 46 | memset(sniffer_device, 0, sizeof(sniffer_device)); |
30 | strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); | 47 | strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); |
31 | 48 | ||
32 | /* Set card type */ | 49 | /* Set card type */ |
33 | card_type = atoi(argv[2]); | 50 | card_type = atoi(argv[2]); |
34 | if(card_type < 1 || card_type > 3) | 51 | if(card_type < 1 || card_type > 3) |
35 | usage(); | 52 | usage(); |
36 | 53 | ||
37 | if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) | 54 | if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) |
38 | { | 55 | { |
39 | wl_logerr("Cannot initialize the wireless-card, aborting"); | 56 | wl_logerr("Cannot initialize the wireless-card, aborting"); |
40 | exit(-1); | 57 | exit(-1); |
41 | } | 58 | } |
42 | wl_loginfo("Set card into monitor mode"); | 59 | wl_loginfo("Set card into monitor mode"); |
43 | 60 | ||
44 | /////// following line will be moved to lib as soon as possible //////////// | 61 | /////// following line will be moved to lib as soon as possible //////////// |
45 | if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) | 62 | if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) |
46 | { | 63 | { |
47 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | 64 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); |
48 | exit(-1); | 65 | exit(-1); |
49 | } | 66 | } |
50 | 67 | ||
51 | #ifdef HAVE_PCAP_NONBLOCK | 68 | #ifdef HAVE_PCAP_NONBLOCK |
52 | pcap_setnonblock(handletopcap, 1, NULL); | 69 | pcap_setnonblock(handletopcap, 1, NULL); |
53 | #endif | 70 | #endif |
54 | 71 | ||
55 | //////////////////////////////////////// | 72 | //////////////////////////////////////// |
56 | 73 | ||
57 | /* Setup socket for incoming commands */ | 74 | /* Setup socket for incoming commands */ |
58 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) | 75 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) |
59 | { | 76 | { |
60 | wl_logerr("Cannot setup socket"); | 77 | wl_logerr("Cannot setup socket"); |
61 | exit(-1); | 78 | exit(-1); |
62 | } | 79 | } |
63 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 80 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
64 | 81 | ||
65 | FD_ZERO(&rset); | 82 | FD_ZERO(&rset); |
66 | 83 | ||
67 | /* Start main loop */ | 84 | /* Start main loop */ |
68 | wl_loginfo("Starting main loop"); | 85 | wl_loginfo("Starting main loop"); |
69 | while(1) | 86 | while(1) |
70 | { | 87 | { |
71 | 88 | ||
72 | FD_SET(sock, &rset); | 89 | FD_SET(sock, &rset); |
73 | FD_SET(pcap_fileno(handletopcap), &rset); | 90 | FD_SET(pcap_fileno(handletopcap), &rset); |
74 | 91 | ||
92 | // blah | ||
93 | timedout=1; | ||
94 | alarm(1); | ||
95 | |||
75 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ | 96 | /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ |
76 | maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; | 97 | maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; |
77 | 98 | ||
78 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 99 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0 && timedout) |
79 | { | 100 | { |
80 | wl_logerr("Error calling select: %s", strerror(errno)); | 101 | wl_logerr("Error calling select: %s", strerror(errno)); |
81 | break; | 102 | break; |
82 | } | 103 | } |
83 | 104 | ||
84 | /* Got data on local socket from GUI */ | 105 | /* Got data on local socket from GUI */ |
85 | if(FD_ISSET(sock, &rset)) | 106 | if(FD_ISSET(sock, &rset)) |
86 | { | 107 | { |
87 | /* Receive data from socket */ | 108 | /* Receive data from socket */ |
88 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) | 109 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0 && timedout) |
89 | { | 110 | { |
90 | wl_logerr("Error trying to read: %s", strerror(errno)); | 111 | wl_logerr("Error trying to read: %s", strerror(errno)); |
91 | break; | 112 | break; |
92 | } | 113 | } |
93 | else | 114 | else |
94 | { | 115 | { |
95 | /* check type of packet and start function according to it */ | 116 | /* check type of packet and start function according to it */ |
96 | switch(retval) | 117 | switch(retval) |
97 | { | 118 | { |
98 | case 98: | 119 | case 98: |
99 | wl_loginfo("Received STARTSNIFF command"); | 120 | wl_loginfo("Received STARTSNIFF command"); |
100 | break; | 121 | break; |
101 | case 99: | 122 | case 99: |
102 | wl_loginfo("Received STOPSNIFF command"); | 123 | wl_loginfo("Received STOPSNIFF command"); |
103 | break; | 124 | break; |
104 | default: | 125 | default: |
105 | wl_logerr("Received unknown command: %d", retval); | 126 | wl_logerr("Received unknown command: %d", retval); |
106 | break; | 127 | break; |
107 | } | 128 | } |
108 | } | 129 | } |
109 | } /* FD_ISSET */ | 130 | } /* FD_ISSET */ |
110 | 131 | ||
111 | /* Check pcap lib for packets */ | 132 | /* Check pcap lib for packets */ |
112 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 133 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
113 | { | 134 | { |
114 | 135 | ||
115 | /* Grab one single packet */ | 136 | /* Grab one single packet */ |
116 | packet = pcap_next(handletopcap, &header); | 137 | packet = pcap_next(handletopcap, &header); |
117 | 138 | ||
118 | /* process the packet */ | 139 | /* process the packet */ |
119 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | 140 | process_packets(&header,*&packet, GUIADDR, GUIPORT); |
120 | } | 141 | } |
121 | 142 | ||
122 | } /* while(1) */ | 143 | } /* while(1) */ |
123 | 144 | ||
124 | close(sock); | 145 | close(sock); |
125 | exit(0); | 146 | exit(0); |
126 | } | 147 | } |
127 | 148 | ||
128 | void usage(void) | 149 | void usage(void) |
129 | { | 150 | { |
130 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | 151 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ |
131 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | 152 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ |
132 | "\t<cardtype> = Cardtype:\t Cisco\t= 1\n" \ | 153 | "\t<cardtype> = Cardtype:\t Cisco\t= 1\n" \ |
133 | "\t\t\t\tNG\t= 2\n" \ | 154 | "\t\t\t\tNG\t= 2\n" \ |
134 | "\t\t\t\tHOSTAP\t= 3\n"); | 155 | "\t\t\t\tHOSTAP\t= 3\n"); |
135 | exit(-1); | 156 | exit(-1); |
136 | } | 157 | } |