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 | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 1f9e98a..a2e1f96 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -9,87 +9,105 @@ | |||
9 | #include "cardmode.hh" | 9 | #include "cardmode.hh" |
10 | #include "sniffer.hh" | 10 | #include "sniffer.hh" |
11 | 11 | ||
12 | /* Main function of wellenreiterd */ | 12 | /* Main function of wellenreiterd */ |
13 | int main(int argc, char **argv) | 13 | int main(int argc, char **argv) |
14 | { | 14 | { |
15 | int sock, maxfd; | 15 | int sock, maxfd, retval; |
16 | struct sockaddr_in *cliaddr; | ||
17 | socklen_t len=sizeof(struct sockaddr); | ||
18 | char buffer[128]; | 16 | char buffer[128]; |
19 | pcap_t *handletopcap; /* The handle to the libpcap */ | 17 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | 18 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ |
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | 19 | struct pcap_pkthdr header; /* The packet header from pcap*/ |
22 | const u_char *packet; /* The actual packet content*/ | 20 | const u_char *packet; /* The actual packet content*/ |
23 | 21 | ||
24 | fd_set rset; | 22 | fd_set rset; |
25 | 23 | ||
26 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 24 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
27 | 25 | ||
26 | #if 0 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | 27 | /* will be replaced soon, just for max because max is lazy :-) */ |
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | 28 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) |
30 | { | 29 | { |
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | 30 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); |
32 | exit(-1); | 31 | exit(-1); |
33 | } | 32 | } |
33 | #endif | ||
34 | 34 | ||
35 | /* opening the pcap for sniffing */ | 35 | /* opening the pcap for sniffing */ |
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | 36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); |
37 | #ifdef HAVE_PCAP_NONBLOCK | 37 | #ifdef HAVE_PCAP_NONBLOCK |
38 | pcap_setnonblock(handletopcap, 1, errstr); | 38 | pcap_setnonblock(handletopcap, 1, errstr); |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) | 42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) |
43 | { | 43 | { |
44 | wl_logerr("Cannot setup socket"); | 44 | wl_logerr("Cannot setup socket"); |
45 | exit(-1); | 45 | exit(-1); |
46 | } | 46 | } |
47 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 47 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
48 | 48 | ||
49 | FD_ZERO(&rset); | 49 | FD_ZERO(&rset); |
50 | 50 | ||
51 | /* Start main loop */ | 51 | /* Start main loop */ |
52 | wl_loginfo("Starting main loop"); | 52 | wl_loginfo("Starting main loop"); |
53 | while(1) | 53 | while(1) |
54 | { | 54 | { |
55 | 55 | ||
56 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
57 | FD_SET(pcap_fileno(handletopcap), &rset); | 57 | // FD_SET(pcap_fileno(handletopcap), &rset); |
58 | maxfd=sock + pcap_fileno(handletopcap) + 1; | 58 | // maxfd=sock + pcap_fileno(handletopcap) + 1; |
59 | maxfd=sock + 1; | ||
59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 60 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
60 | { | 61 | { |
61 | wl_logerr("Error calling select: %s", strerror(errno)); | 62 | wl_logerr("Error calling select: %s", strerror(errno)); |
62 | break; | 63 | break; |
63 | } | 64 | } |
64 | 65 | ||
65 | /* Got data on local socket from GUI */ | 66 | /* Got data on local socket from GUI */ |
66 | if(FD_ISSET(sock, &rset)) | 67 | if(FD_ISSET(sock, &rset)) |
67 | { | 68 | { |
68 | memset(buffer, 0, sizeof(buffer)); | 69 | |
69 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | 70 | if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0) |
70 | { | 71 | { |
71 | wl_logerr("Cannot read from socket: %s", strerror(errno)); | 72 | wl_logerr("Error trying to read: %s", strerror(errno)); |
72 | break; | 73 | break; |
73 | } | 74 | } |
74 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | 75 | else |
75 | 76 | { | |
76 | /* will be passed to analyze function */ | 77 | switch(retval) |
77 | fprintf(stderr, "Received command: %s\n", buffer); | 78 | { |
78 | 79 | case 98: | |
79 | } | 80 | { |
80 | 81 | wl_loginfo("Received STARTSNIFF command"); | |
82 | break; | ||
83 | }; | ||
84 | case 99: | ||
85 | { | ||
86 | wl_loginfo("Received STOPSNIFF command"); | ||
87 | break; | ||
88 | }; | ||
89 | default: | ||
90 | { | ||
91 | wl_logerr("Received unknown command: %d", retval); | ||
92 | break; | ||
93 | }; | ||
94 | } | ||
95 | } | ||
96 | } /* FD_ISSET */ | ||
97 | |||
98 | #if 0 | ||
81 | /* Pcap stuff */ | 99 | /* Pcap stuff */ |
82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 100 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
83 | { | 101 | { |
84 | 102 | ||
85 | /* Grab one single packet */ | 103 | /* Grab one single packet */ |
86 | packet = pcap_next(handletopcap, &header); | 104 | packet = pcap_next(handletopcap, &header); |
87 | 105 | ||
88 | /* process the packet */ | 106 | /* process the packet */ |
89 | process_packets(NULL,&header,*&packet); | 107 | process_packets(NULL,&header,*&packet); |
90 | |||
91 | } | 108 | } |
109 | #endif | ||
92 | } | 110 | } |
93 | close(sock); | 111 | close(sock); |
94 | exit(0); | 112 | exit(0); |
95 | } | 113 | } |