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 | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 8724efa..b3a37b6 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -3,81 +3,79 @@ | |||
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 "log.hh" | ||
10 | #include "sendgui.hh" | ||
11 | #include "getgui.hh" | ||
12 | 9 | ||
13 | /* Main function of wellenreiterd */ | 10 | /* Main function of wellenreiterd */ |
14 | int main(int argc, char **argv) | 11 | int main(int argc, char **argv) |
15 | { | 12 | { |
16 | int sock, maxfd; | 13 | int sock, maxfd, guiport=GUIPORT; |
14 | char guihost[]="127.0.0.1"; | ||
17 | struct sockaddr_in *cliaddr; | 15 | struct sockaddr_in *cliaddr; |
18 | socklen_t len=sizeof(struct sockaddr); | 16 | socklen_t len=sizeof(struct sockaddr); |
19 | char buffer[128]; | 17 | char buffer[128]; |
20 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 18 | FILE *fp=stdin; /* Will be replaced with sniffer */ |
21 | fd_set rset; | 19 | fd_set rset; |
22 | 20 | ||
23 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 21 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
24 | 22 | ||
25 | /* Setup socket for incoming commands */ | 23 | /* Setup socket for incoming commands */ |
26 | if(!commsock(&sock)) | 24 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) |
27 | return 0; | 25 | { |
28 | 26 | wl_logerr("Cannot setup socket"); | |
29 | log_info("Set up socket '%d' for GUI communication", sock); | 27 | exit(-1); |
28 | } | ||
29 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | ||
30 | 30 | ||
31 | FD_ZERO(&rset); | 31 | FD_ZERO(&rset); |
32 | 32 | ||
33 | /* Start main loop */ | 33 | /* Start main loop */ |
34 | log_info("Starting main loop"); | 34 | wl_loginfo("Starting main loop"); |
35 | while(1) | 35 | while(1) |
36 | { | 36 | { |
37 | 37 | ||
38 | FD_SET(sock, &rset); | 38 | FD_SET(sock, &rset); |
39 | FD_SET(fileno(fp), &rset); | 39 | FD_SET(fileno(fp), &rset); |
40 | maxfd=sock+fileno(fp)+1; | 40 | maxfd=sock+fileno(fp)+1; |
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
42 | { | 42 | { |
43 | log_err("Error calling select: %s", strerror(errno)); | 43 | wl_logerr("Error calling select: %s", strerror(errno)); |
44 | break; | 44 | break; |
45 | } | 45 | } |
46 | 46 | ||
47 | /* Got data on local socket from GUI */ | 47 | /* Got data on local socket from GUI */ |
48 | if(FD_ISSET(sock, &rset)) | 48 | if(FD_ISSET(sock, &rset)) |
49 | { | 49 | { |
50 | memset(buffer, 0, sizeof(buffer)); | 50 | memset(buffer, 0, sizeof(buffer)); |
51 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | 51 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) |
52 | { | 52 | { |
53 | log_err("Cannot read from socket: %s", strerror(errno)); | 53 | wl_logerr("Cannot read from socket: %s", strerror(errno)); |
54 | break; | 54 | break; |
55 | } | 55 | } |
56 | log_info("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | 56 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); |
57 | 57 | ||
58 | /* Pass string to analyze function */ | 58 | /* Pass string to analyze function */ |
59 | commstring(buffer); | 59 | // sendcomm(guihost, guiport, buffer); |
60 | 60 | ||
61 | } | 61 | } |
62 | 62 | ||
63 | /* Will be replaced with sniffer ... later */ | 63 | /* Will be replaced with sniffer ... later */ |
64 | if(FD_ISSET(fileno(fp), &rset)) | 64 | if(FD_ISSET(fileno(fp), &rset)) |
65 | { | 65 | { |
66 | memset(buffer, 0, sizeof(buffer)); | 66 | memset(buffer, 0, sizeof(buffer)); |
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | 67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) |
68 | { | 68 | { |
69 | log_err("Cannot read from stdin: %s", strerror(errno)); | 69 | wl_logerr("Cannot read from stdin: %s", strerror(errno)); |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | log_info("Sending command to '%s': %s", GUIADDR, buffer); | 72 | wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer); |
73 | 73 | ||
74 | /* Send string to GUI */ | 74 | /* Send string to GUI */ |
75 | sendgui("%d: %s", 1234, buffer); | 75 | sendcomm(guihost, guiport, "%d: %s", 1234, buffer); |
76 | 76 | ||
77 | } | 77 | } |
78 | |||
79 | } | 78 | } |
80 | |||
81 | close(sock); | 79 | close(sock); |
82 | return 0; | 80 | exit(0); |
83 | } | 81 | } |