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