author | mjm <mjm> | 2003-02-26 22:17:26 (UTC) |
---|---|---|
committer | mjm <mjm> | 2003-02-26 22:17:26 (UTC) |
commit | ed168abe1c9c1384b0151ea9b49a7e364f9b67be (patch) (unidiff) | |
tree | 4364879aaa3c6fe8d963256a36717efc1b24d03c | |
parent | 60da6fed3516c5cb73930d0d2cdae253a16c12f8 (diff) | |
download | opie-ed168abe1c9c1384b0151ea9b49a7e364f9b67be.zip opie-ed168abe1c9c1384b0151ea9b49a7e364f9b67be.tar.gz opie-ed168abe1c9c1384b0151ea9b49a7e364f9b67be.tar.bz2 |
added ok and fail msgs for gui
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index d77d987..3a28217 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -75,103 +75,107 @@ int main(int argc, char **argv) | |||
75 | { | 75 | { |
76 | wl_logerr("Cannot create thread: %s", strerror(errno)); | 76 | wl_logerr("Cannot create thread: %s", strerror(errno)); |
77 | close(sock); | 77 | close(sock); |
78 | exit(EXIT_FAILURE); | 78 | exit(EXIT_FAILURE); |
79 | } | 79 | } |
80 | if(pthread_detach(sub)) | 80 | if(pthread_detach(sub)) |
81 | { | 81 | { |
82 | wl_logerr("Error detaching thread"); | 82 | wl_logerr("Error detaching thread"); |
83 | close(sock); | 83 | close(sock); |
84 | pthread_exit((pthread_t *)sub); | 84 | pthread_exit((pthread_t *)sub); |
85 | exit(EXIT_FAILURE); | 85 | exit(EXIT_FAILURE); |
86 | } | 86 | } |
87 | wl_loginfo("Created and detached channel switching thread"); | 87 | wl_loginfo("Created and detached channel switching thread"); |
88 | 88 | ||
89 | FD_ZERO(&rset); | 89 | FD_ZERO(&rset); |
90 | 90 | ||
91 | /* Start main loop */ | 91 | /* Start main loop */ |
92 | wl_loginfo("Starting main loop"); | 92 | wl_loginfo("Starting main loop"); |
93 | while(1) | 93 | while(1) |
94 | { | 94 | { |
95 | 95 | ||
96 | FD_SET(sock, &rset); | 96 | FD_SET(sock, &rset); |
97 | FD_SET(pcap_fileno(handletopcap), &rset); | 97 | FD_SET(pcap_fileno(handletopcap), &rset); |
98 | 98 | ||
99 | /* maxfd = biggest filefd */ | 99 | /* maxfd = biggest filefd */ |
100 | maxfd = (sock > pcap_fileno(handletopcap) ? | 100 | maxfd = (sock > pcap_fileno(handletopcap) ? |
101 | sock + 1 : pcap_fileno(handletopcap)) + 1; | 101 | sock + 1 : pcap_fileno(handletopcap)) + 1; |
102 | 102 | ||
103 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 103 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
104 | { | 104 | { |
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 STARTSNIFF: |
124 | wl_loginfo("Received STARTSNIFF command"); | 124 | wl_loginfo("Received STARTSNIFF command"); |
125 | break; | 125 | if(!send_ok(GUIADDR, GUIPORT, STARTSNIFF)) |
126 | case 99: | 126 | wl_logerr("Cannot set OK_CMD to GUI"); |
127 | wl_loginfo("Received STOPSNIFF command"); | 127 | break; |
128 | break; | 128 | case STOPSNIFF: |
129 | default: | 129 | wl_loginfo("Received STOPSNIFF command"); |
130 | if(!send_ok(GUIADDR, GUIPORT, STOPSNIFF)) | ||
131 | wl_logerr("Cannot set FAIL_CMD to GUI"); | ||
132 | break; | ||
133 | default: | ||
130 | wl_logerr("Received unknown command: %d", retval); | 134 | wl_logerr("Received unknown command: %d", retval); |
131 | break; | 135 | break; |
132 | } | 136 | } |
133 | } | 137 | } |
134 | } /* FD_ISSET */ | 138 | } /* FD_ISSET */ |
135 | 139 | ||
136 | /* Check pcap lib for packets */ | 140 | /* Check pcap lib for packets */ |
137 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 141 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
138 | { | 142 | { |
139 | 143 | ||
140 | /* Grab one single packet */ | 144 | /* Grab one single packet */ |
141 | packet = pcap_next(handletopcap, &header); | 145 | packet = pcap_next(handletopcap, &header); |
142 | 146 | ||
143 | /* process the packet */ | 147 | /* process the packet */ |
144 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | 148 | process_packets(&header,*&packet, GUIADDR, GUIPORT); |
145 | } | 149 | } |
146 | 150 | ||
147 | } /* while(1) */ | 151 | } /* while(1) */ |
148 | 152 | ||
149 | close(sock); | 153 | close(sock); |
150 | exit(EXIT_SUCCESS); | 154 | exit(EXIT_SUCCESS); |
151 | } | 155 | } |
152 | 156 | ||
153 | void | 157 | void |
154 | usage(void) | 158 | usage(void) |
155 | { | 159 | { |
156 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | 160 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ |
157 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | 161 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ |
158 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ | 162 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ |
159 | "\t\t\t\tNG\t= 2\n" \ | 163 | "\t\t\t\tNG\t= 2\n" \ |
160 | "\t\t\t\tHOSTAP\t= 3\n" \ | 164 | "\t\t\t\tHOSTAP\t= 3\n" \ |
161 | "\t\t\t\tLUCENT\t= 4\n"); | 165 | "\t\t\t\tLUCENT\t= 4\n"); |
162 | exit(EXIT_FAILURE); | 166 | exit(EXIT_FAILURE); |
163 | } | 167 | } |
164 | 168 | ||
165 | void * | 169 | void * |
166 | channel_switcher(void *cardtypeptr) | 170 | channel_switcher(void *cardtypeptr) |
167 | { | 171 | { |
168 | wl_cardtype_t *cardtype; | 172 | wl_cardtype_t *cardtype; |
169 | int maxchan=0; | 173 | int maxchan=0; |
170 | int channel=1; | 174 | int channel=1; |
171 | /* Get card info struct */ | 175 | /* Get card info struct */ |
172 | cardtype = (wl_cardtype_t *)cardtypeptr; | 176 | cardtype = (wl_cardtype_t *)cardtypeptr; |
173 | /* Get from the wireless extension the amount of available channels | 177 | /* Get from the wireless extension the amount of available channels |
174 | this prevents a fail in switching on us cards */ | 178 | this prevents a fail in switching on us cards */ |
175 | maxchan = card_detect_channels(cardtype->iface); | 179 | maxchan = card_detect_channels(cardtype->iface); |
176 | 180 | ||
177 | if (maxchan < MAXCHANNEL) | 181 | if (maxchan < MAXCHANNEL) |