-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 46a50ed..d77d987 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -105,89 +105,98 @@ int main(int argc, char **argv) | |||
105 | wl_logerr("Error calling select: %s", strerror(errno)); | 105 | wl_logerr("Error calling select: %s", strerror(errno)); |
106 | break; | 106 | break; |
107 | } | 107 | } |
108 | 108 | ||
109 | /* Got data on local socket from GUI */ | 109 | /* Got data on local socket from GUI */ |
110 | if(FD_ISSET(sock, &rset)) | 110 | if(FD_ISSET(sock, &rset)) |
111 | { | 111 | { |
112 | /* Receive data from socket */ | 112 | /* Receive data from socket */ |
113 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) | 113 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) |
114 | { | 114 | { |
115 | wl_logerr("Error trying to read: %s", strerror(errno)); | 115 | wl_logerr("Error trying to read: %s", strerror(errno)); |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | else | 118 | else |
119 | { | 119 | { |
120 | /* check type of packet and start function according to it */ | 120 | /* check type of packet and start function according to it */ |
121 | switch(retval) | 121 | switch(retval) |
122 | { | 122 | { |
123 | case 98: | 123 | case 98: |
124 | wl_loginfo("Received STARTSNIFF command"); | 124 | wl_loginfo("Received STARTSNIFF command"); |
125 | break; | 125 | break; |
126 | case 99: | 126 | case 99: |
127 | wl_loginfo("Received STOPSNIFF command"); | 127 | wl_loginfo("Received STOPSNIFF command"); |
128 | break; | 128 | break; |
129 | default: | 129 | default: |
130 | wl_logerr("Received unknown command: %d", retval); | 130 | wl_logerr("Received unknown command: %d", retval); |
131 | break; | 131 | break; |
132 | } | 132 | } |
133 | } | 133 | } |
134 | } /* FD_ISSET */ | 134 | } /* FD_ISSET */ |
135 | 135 | ||
136 | /* Check pcap lib for packets */ | 136 | /* Check pcap lib for packets */ |
137 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 137 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
138 | { | 138 | { |
139 | 139 | ||
140 | /* Grab one single packet */ | 140 | /* Grab one single packet */ |
141 | packet = pcap_next(handletopcap, &header); | 141 | packet = pcap_next(handletopcap, &header); |
142 | 142 | ||
143 | /* process the packet */ | 143 | /* process the packet */ |
144 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | 144 | process_packets(&header,*&packet, GUIADDR, GUIPORT); |
145 | } | 145 | } |
146 | 146 | ||
147 | } /* while(1) */ | 147 | } /* while(1) */ |
148 | 148 | ||
149 | close(sock); | 149 | close(sock); |
150 | exit(EXIT_SUCCESS); | 150 | exit(EXIT_SUCCESS); |
151 | } | 151 | } |
152 | 152 | ||
153 | void | 153 | void |
154 | usage(void) | 154 | usage(void) |
155 | { | 155 | { |
156 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | 156 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ |
157 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | 157 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ |
158 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ | 158 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ |
159 | "\t\t\t\tNG\t= 2\n" \ | 159 | "\t\t\t\tNG\t= 2\n" \ |
160 | "\t\t\t\tHOSTAP\t= 3\n" \ | 160 | "\t\t\t\tHOSTAP\t= 3\n" \ |
161 | "\t\t\t\tLUCENT\t= 4\n"); | 161 | "\t\t\t\tLUCENT\t= 4\n"); |
162 | exit(EXIT_FAILURE); | 162 | exit(EXIT_FAILURE); |
163 | } | 163 | } |
164 | 164 | ||
165 | void * | 165 | void * |
166 | channel_switcher(void *cardtypeptr) | 166 | channel_switcher(void *cardtypeptr) |
167 | { | 167 | { |
168 | wl_cardtype_t *cardtype; | 168 | wl_cardtype_t *cardtype; |
169 | int maxchan=0; | ||
169 | int channel=1; | 170 | int channel=1; |
170 | |||
171 | /* Get card info struct */ | 171 | /* Get card info struct */ |
172 | cardtype = (wl_cardtype_t *)cardtypeptr; | 172 | cardtype = (wl_cardtype_t *)cardtypeptr; |
173 | 173 | /* Get from the wireless extension the amount of available channels | |
174 | this prevents a fail in switching on us cards */ | ||
175 | maxchan = card_detect_channels(cardtype->iface); | ||
176 | |||
177 | if (maxchan < MAXCHANNEL) | ||
178 | { | ||
179 | #undef MAXCHANNEL | ||
180 | #define MAXCHANNEL maxchan | ||
181 | } | ||
182 | |||
174 | while(1) | 183 | while(1) |
175 | { | 184 | { |
176 | 185 | ||
177 | /* If channel bigger than maxchannel, set to 1 */ | 186 | /* If channel bigger than maxchannel, set to 1 */ |
178 | if(channel > MAXCHANNEL) | 187 | if(channel > MAXCHANNEL) |
179 | channel=1; | 188 | channel=1; |
180 | 189 | ||
181 | /* Set channel */ | 190 | /* Set channel */ |
182 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) | 191 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) |
183 | { | 192 | { |
184 | wl_logerr("Cannot set channel, thread exiting"); | 193 | wl_logerr("Cannot set channel, thread exiting"); |
185 | pthread_exit(NULL); | 194 | pthread_exit(NULL); |
186 | } | 195 | } |
187 | 196 | ||
188 | /* sleep */ | 197 | /* sleep */ |
189 | usleep(CHANINTERVAL); | 198 | usleep(CHANINTERVAL); |
190 | 199 | ||
191 | channel++; | 200 | channel++; |
192 | } /* while */ | 201 | } /* while */ |
193 | } | 202 | } |