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