author | mickeyl <mickeyl> | 2003-03-30 01:51:14 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-30 01:51:14 (UTC) |
commit | d11a0154e2d9732854c9a3d598857bc20f359849 (patch) (unidiff) | |
tree | af0e0273d01f4f6c64c9f230f22bb91a7a8a21d8 /noncore/net/wellenreiter/daemon/source/daemon.cc | |
parent | 99899abc80a8aa05044eeecd8a061b0a8efaa713 (diff) | |
download | opie-d11a0154e2d9732854c9a3d598857bc20f359849.zip opie-d11a0154e2d9732854c9a3d598857bc20f359849.tar.gz opie-d11a0154e2d9732854c9a3d598857bc20f359849.tar.bz2 |
- the network work for libopie2 pays off...
- good bye to wellenreiterd, t'was fun but always too unstable and too hard to maintain
- good bye to libwellenreiter
Diffstat (limited to 'noncore/net/wellenreiter/daemon/source/daemon.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 195 |
1 files changed, 0 insertions, 195 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc deleted file mode 100644 index b840f17..0000000 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | /* | ||
2 | * Startup functions of wellenreiter | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "config.hh" | ||
8 | #include "daemon.hh" | ||
9 | |||
10 | /* should be parsed from cfg-file */ | ||
11 | #define MAXCHANNEL 13 | ||
12 | #define CHANINTERVAL 500000 | ||
13 | |||
14 | |||
15 | /* Main function of wellenreiterd */ | ||
16 | int main(int argc, char **argv) | ||
17 | { | ||
18 | int sock, maxfd, retval; | ||
19 | char buffer[WL_SOCKBUF]; | ||
20 | struct pcap_pkthdr header; | ||
21 | struct sockaddr_in saddr; | ||
22 | // pcap_t *handletopcap; | ||
23 | wl_cardtype_t cardtype; | ||
24 | pthread_t sub; | ||
25 | const unsigned char *packet; | ||
26 | |||
27 | fd_set rset; | ||
28 | |||
29 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | ||
30 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | ||
31 | |||
32 | if(argc < 3) | ||
33 | usage(); | ||
34 | |||
35 | /* Set sniffer device */ | ||
36 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); | ||
37 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); | ||
38 | |||
39 | /* Set card type */ | ||
40 | cardtype.type = atoi(argv[2]); | ||
41 | if(cardtype.type < 1 || cardtype.type > 4) | ||
42 | usage(); | ||
43 | |||
44 | /* Until we do not act as a read daemon, it starts the sniffer | ||
45 | right after startup */ | ||
46 | if (!start_sniffer(cardtype.iface,cardtype.type)) | ||
47 | { | ||
48 | wl_logerr("daemon, start_sniff did not return proper, aborting"); | ||
49 | exit(EXIT_FAILURE); | ||
50 | } | ||
51 | wl_loginfo ("daemon, wireless card prepared for sniffing"); | ||
52 | |||
53 | /* Setup socket for incoming commands */ | ||
54 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) | ||
55 | { | ||
56 | wl_logerr("Cannot setup socket"); | ||
57 | exit(EXIT_FAILURE); | ||
58 | } | ||
59 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | ||
60 | |||
61 | /* Create channelswitching thread */ | ||
62 | if(pthread_create(&sub, NULL, channel_switcher, | ||
63 | (void *)&cardtype) != 0) | ||
64 | { | ||
65 | wl_logerr("Cannot create thread: %s", strerror(errno)); | ||
66 | close(sock); | ||
67 | exit(EXIT_FAILURE); | ||
68 | } | ||
69 | if(pthread_detach(sub)) | ||
70 | { | ||
71 | wl_logerr("Error detaching thread"); | ||
72 | close(sock); | ||
73 | pthread_exit((pthread_t *)sub); | ||
74 | exit(EXIT_FAILURE); | ||
75 | } | ||
76 | wl_loginfo("Created and detached channel switching thread"); | ||
77 | |||
78 | FD_ZERO(&rset); | ||
79 | |||
80 | /* Start main loop */ | ||
81 | wl_loginfo("Starting main loop"); | ||
82 | while(1) | ||
83 | { | ||
84 | |||
85 | FD_SET(sock, &rset); | ||
86 | FD_SET(pcap_fileno(handletopcap), &rset); | ||
87 | |||
88 | /* maxfd = biggest filefd */ | ||
89 | maxfd = (sock > pcap_fileno(handletopcap) ? | ||
90 | sock + 1 : pcap_fileno(handletopcap)) + 1; | ||
91 | |||
92 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | ||
93 | { | ||
94 | wl_logerr("Error calling select: %s", strerror(errno)); | ||
95 | break; | ||
96 | } | ||
97 | |||
98 | /* Got data on local socket from GUI */ | ||
99 | if(FD_ISSET(sock, &rset)) | ||
100 | { | ||
101 | /* Receive data from socket */ | ||
102 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) | ||
103 | { | ||
104 | wl_logerr("Error trying to read: %s", strerror(errno)); | ||
105 | break; | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | /* check type of packet and start function according to it */ | ||
110 | switch(retval) | ||
111 | { | ||
112 | case STARTSNIFF: | ||
113 | wl_loginfo("Received STARTSNIFF command"); | ||
114 | if(!send_ok(GUIADDR, GUIPORT, STARTSNIFF)) | ||
115 | wl_logerr("Cannot set OK_CMD to GUI"); | ||
116 | break; | ||
117 | case STOPSNIFF: | ||
118 | wl_loginfo("Received STOPSNIFF command"); | ||
119 | if(!send_ok(GUIADDR, GUIPORT, STOPSNIFF)) | ||
120 | wl_logerr("Cannot set FAIL_CMD to GUI"); | ||
121 | break; | ||
122 | default: | ||
123 | wl_logerr("Received unknown command: %d", retval); | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | } /* FD_ISSET */ | ||
128 | |||
129 | /* Check pcap lib for packets */ | ||
130 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | ||
131 | { | ||
132 | |||
133 | /* Grab one single packet */ | ||
134 | packet = pcap_next(handletopcap, &header); | ||
135 | |||
136 | /* process the packet */ | ||
137 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | ||
138 | } | ||
139 | |||
140 | } /* while(1) */ | ||
141 | |||
142 | close(sock); | ||
143 | exit(EXIT_SUCCESS); | ||
144 | } | ||
145 | |||
146 | void | ||
147 | usage(void) | ||
148 | { | ||
149 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | ||
150 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | ||
151 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ | ||
152 | "\t\t\t\tNG\t= 2\n" \ | ||
153 | "\t\t\t\tHOSTAP\t= 3\n" \ | ||
154 | "\t\t\t\tLUCENT\t= 4\n"); | ||
155 | exit(EXIT_FAILURE); | ||
156 | } | ||
157 | |||
158 | void * | ||
159 | channel_switcher(void *cardtypeptr) | ||
160 | { | ||
161 | wl_cardtype_t *cardtype; | ||
162 | int maxchan=0; | ||
163 | int channel=1; | ||
164 | /* Get card info struct */ | ||
165 | cardtype = (wl_cardtype_t *)cardtypeptr; | ||
166 | /* Get from the wireless extension the amount of available channels | ||
167 | this prevents a fail in switching on us cards */ | ||
168 | maxchan = card_detect_channels(cardtype->iface); | ||
169 | |||
170 | if (maxchan < MAXCHANNEL) | ||
171 | { | ||
172 | #undef MAXCHANNEL | ||
173 | #define MAXCHANNEL maxchan | ||
174 | } | ||
175 | |||
176 | while(1) | ||
177 | { | ||
178 | |||
179 | /* If channel bigger than maxchannel, set to 1 */ | ||
180 | if(channel > MAXCHANNEL) | ||
181 | channel=1; | ||
182 | |||
183 | /* Set channel */ | ||
184 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) | ||
185 | { | ||
186 | wl_logerr("Cannot set channel, thread exiting"); | ||
187 | pthread_exit(NULL); | ||
188 | } | ||
189 | |||
190 | /* sleep */ | ||
191 | usleep(CHANINTERVAL); | ||
192 | |||
193 | channel++; | ||
194 | } /* while */ | ||
195 | } | ||