Diffstat (limited to 'noncore/net/wellenreiter/daemon/source/daemon.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index b3a37b6..1f9e98a 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -3,26 +3,44 @@ | |||
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 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | ||
9 | 11 | ||
10 | /* Main function of wellenreiterd */ | 12 | /* Main function of wellenreiterd */ |
11 | int main(int argc, char **argv) | 13 | int main(int argc, char **argv) |
12 | { | 14 | { |
13 | int sock, maxfd, guiport=GUIPORT; | 15 | int sock, maxfd; |
14 | char guihost[]="127.0.0.1"; | ||
15 | struct sockaddr_in *cliaddr; | 16 | struct sockaddr_in *cliaddr; |
16 | socklen_t len=sizeof(struct sockaddr); | 17 | socklen_t len=sizeof(struct sockaddr); |
17 | char buffer[128]; | 18 | char buffer[128]; |
18 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 19 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
22 | const u_char *packet; /* The actual packet content*/ | ||
23 | |||
19 | fd_set rset; | 24 | fd_set rset; |
20 | 25 | ||
21 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 26 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
22 | 27 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | ||
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
30 | { | ||
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | ||
32 | exit(-1); | ||
33 | } | ||
34 | |||
35 | /* opening the pcap for sniffing */ | ||
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | ||
37 | #ifdef HAVE_PCAP_NONBLOCK | ||
38 | pcap_setnonblock(handletopcap, 1, errstr); | ||
39 | #endif | ||
40 | |||
23 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
24 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) | 42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) |
25 | { | 43 | { |
26 | wl_logerr("Cannot setup socket"); | 44 | wl_logerr("Cannot setup socket"); |
27 | exit(-1); | 45 | exit(-1); |
28 | } | 46 | } |
@@ -33,14 +51,14 @@ int main(int argc, char **argv) | |||
33 | /* Start main loop */ | 51 | /* Start main loop */ |
34 | wl_loginfo("Starting main loop"); | 52 | wl_loginfo("Starting main loop"); |
35 | while(1) | 53 | while(1) |
36 | { | 54 | { |
37 | 55 | ||
38 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
39 | FD_SET(fileno(fp), &rset); | 57 | FD_SET(pcap_fileno(handletopcap), &rset); |
40 | maxfd=sock+fileno(fp)+1; | 58 | maxfd=sock + pcap_fileno(handletopcap) + 1; |
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
42 | { | 60 | { |
43 | wl_logerr("Error calling select: %s", strerror(errno)); | 61 | wl_logerr("Error calling select: %s", strerror(errno)); |
44 | break; | 62 | break; |
45 | } | 63 | } |
46 | 64 | ||
@@ -52,30 +70,26 @@ int main(int argc, char **argv) | |||
52 | { | 70 | { |
53 | wl_logerr("Cannot read from socket: %s", strerror(errno)); | 71 | wl_logerr("Cannot read from socket: %s", strerror(errno)); |
54 | break; | 72 | break; |
55 | } | 73 | } |
56 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | 74 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); |
57 | 75 | ||
58 | /* Pass string to analyze function */ | 76 | /* will be passed to analyze function */ |
59 | // sendcomm(guihost, guiport, buffer); | 77 | fprintf(stderr, "Received command: %s\n", buffer); |
60 | 78 | ||
61 | } | 79 | } |
62 | 80 | ||
63 | /* Will be replaced with sniffer ... later */ | 81 | /* Pcap stuff */ |
64 | if(FD_ISSET(fileno(fp), &rset)) | 82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
65 | { | 83 | { |
66 | memset(buffer, 0, sizeof(buffer)); | ||
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | ||
68 | { | ||
69 | wl_logerr("Cannot read from stdin: %s", strerror(errno)); | ||
70 | break; | ||
71 | } | ||
72 | wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer); | ||
73 | 84 | ||
74 | /* Send string to GUI */ | 85 | /* Grab one single packet */ |
75 | sendcomm(guihost, guiport, "%d: %s", 1234, buffer); | 86 | packet = pcap_next(handletopcap, &header); |
87 | |||
88 | /* process the packet */ | ||
89 | process_packets(NULL,&header,*&packet); | ||
76 | 90 | ||
77 | } | 91 | } |
78 | } | 92 | } |
79 | close(sock); | 93 | close(sock); |
80 | exit(0); | 94 | exit(0); |
81 | } | 95 | } |