summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
index b836a31..6467af7 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.cc
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -1,97 +1,119 @@
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 */
11int main(int argc, char **argv) 11int main(int argc, char **argv)
12{ 12{
13 int sock, maxfd, retval; 13 int sock, maxfd, retval;
14 char buffer[128]; 14 char buffer[128];
15 struct pcap_pkthdr header; 15 struct pcap_pkthdr header;
16 pcap_t *handletopcap; 16 pcap_t *handletopcap;
17 const unsigned char *packet; 17 const unsigned char *packet;
18 18
19 fd_set rset; 19 fd_set rset;
20 20
21 fprintf(stderr, "wellenreiterd %s\n\n", VERSION); 21 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
22 22
23 if(!card_into_monitormode(handletopcap, SNIFFER_DEVICE, CARD_TYPE_NG)) 23 if(!card_into_monitormode(&handletopcap, SNIFFER_DEVICE, CARD_TYPE_NG))
24 { 24 {
25 wl_logerr("Cannot set card into mon mode, aborting"); 25 wl_logerr("Cannot set card into mon mode, aborting");
26 exit(-1); 26 exit(-1);
27 } 27 }
28 wl_loginfo("Set card into monitor mode"); 28 wl_loginfo("Set card into monitor mode");
29 29
30 /////// following line will be moved to lib as soon as possible ////////////
31 if((handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 0, NULL)) == NULL)
32 {
33 wl_logerr("pcap_open_live() failed: %s", strerror(errno));
34 exit(-1);
35 }
36
37#ifdef HAVE_PCAP_NONBLOCK
38 pcap_setnonblock(handletopcap, 1, NULL);
39#endif
40
41 /* getting the datalink type */
42 retval = pcap_datalink(handletopcap);
43 if (retval != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
44 {
45 wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", SNIFFER_DEVICE);
46 pcap_close(handletopcap);
47 return 0;
48 }
49 wl_loginfo("Your successfully listen on %s in 802.11 raw mode", SNIFFER_DEVICE);
50 ////////////////////////////////////////
51
30 /* Setup socket for incoming commands */ 52 /* Setup socket for incoming commands */
31 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) 53 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0)
32 { 54 {
33 wl_logerr("Cannot setup socket"); 55 wl_logerr("Cannot setup socket");
34 exit(-1); 56 exit(-1);
35 } 57 }
36 wl_loginfo("Set up socket '%d' for GUI communication", sock); 58 wl_loginfo("Set up socket '%d' for GUI communication", sock);
37 59
38 FD_ZERO(&rset); 60 FD_ZERO(&rset);
39 61
40 /* Start main loop */ 62 /* Start main loop */
41 wl_loginfo("Starting main loop"); 63 wl_loginfo("Starting main loop");
42 while(1) 64 while(1)
43 { 65 {
44 66
45 FD_SET(sock, &rset); 67 FD_SET(sock, &rset);
46 FD_SET(pcap_fileno(handletopcap), &rset); 68 FD_SET(pcap_fileno(handletopcap), &rset);
47 maxfd=sock + pcap_fileno(handletopcap) + 1; 69 maxfd=sock + pcap_fileno(handletopcap) + 1;
48 70
49 if(select(maxfd, &rset, NULL, NULL, NULL) < 0) 71 if(select(maxfd, &rset, NULL, NULL, NULL) < 0)
50 { 72 {
51 wl_logerr("Error calling select: %s", strerror(errno)); 73 wl_logerr("Error calling select: %s", strerror(errno));
52 break; 74 break;
53 } 75 }
54 76
55 /* Got data on local socket from GUI */ 77 /* Got data on local socket from GUI */
56 if(FD_ISSET(sock, &rset)) 78 if(FD_ISSET(sock, &rset))
57 { 79 {
58 /* Receive data from socket */ 80 /* Receive data from socket */
59 if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0) 81 if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0)
60 { 82 {
61 wl_logerr("Error trying to read: %s", strerror(errno)); 83 wl_logerr("Error trying to read: %s", strerror(errno));
62 break; 84 break;
63 } 85 }
64 else 86 else
65 { 87 {
66 /* check type of packet and start function according to it */ 88 /* check type of packet and start function according to it */
67 switch(retval) 89 switch(retval)
68 { 90 {
69 case 98: 91 case 98:
70 wl_loginfo("Received STARTSNIFF command"); 92 wl_loginfo("Received STARTSNIFF command");
71 break; 93 break;
72 case 99: 94 case 99:
73 wl_loginfo("Received STOPSNIFF command"); 95 wl_loginfo("Received STOPSNIFF command");
74 break; 96 break;
75 default: 97 default:
76 wl_logerr("Received unknown command: %d", retval); 98 wl_logerr("Received unknown command: %d", retval);
77 break; 99 break;
78 } 100 }
79 } 101 }
80 } /* FD_ISSET */ 102 } /* FD_ISSET */
81 103
82 /* Check pcap lib for packets */ 104 /* Check pcap lib for packets */
83 if(FD_ISSET(pcap_fileno(handletopcap), &rset)) 105 if(FD_ISSET(pcap_fileno(handletopcap), &rset))
84 { 106 {
85 107
86 /* Grab one single packet */ 108 /* Grab one single packet */
87 packet = pcap_next(handletopcap, &header); 109 packet = pcap_next(handletopcap, &header);
88 110
89 /* process the packet */ 111 /* process the packet */
90 process_packets(&header,*&packet); 112 process_packets(&header,*&packet);
91 } 113 }
92 114
93 } /* while(1) */ 115 } /* while(1) */
94 116
95 close(sock); 117 close(sock);
96 exit(0); 118 exit(0);
97} 119}