author | mjm <mjm> | 2002-11-13 21:57:18 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-11-13 21:57:18 (UTC) |
commit | 9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9 (patch) (unidiff) | |
tree | 427d7e9a07573d295eeabf926d1664ec955331fd | |
parent | d3301ad9a74fdf693551bd70bc3cf34b311eaa49 (diff) | |
download | opie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.zip opie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.tar.gz opie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.tar.bz2 |
sendgui.cc is now udp based
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 1 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sendgui.cc | 47 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sendgui.hh | 1 |
3 files changed, 8 insertions, 41 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 7972c0f..8724efa 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -8,75 +8,76 @@ | |||
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | #include "log.hh" | 9 | #include "log.hh" |
10 | #include "sendgui.hh" | 10 | #include "sendgui.hh" |
11 | #include "getgui.hh" | 11 | #include "getgui.hh" |
12 | 12 | ||
13 | /* Main function of wellenreiterd */ | 13 | /* Main function of wellenreiterd */ |
14 | int main(int argc, char **argv) | 14 | int main(int argc, char **argv) |
15 | { | 15 | { |
16 | int sock, maxfd; | 16 | int sock, maxfd; |
17 | struct sockaddr_in *cliaddr; | 17 | struct sockaddr_in *cliaddr; |
18 | socklen_t len=sizeof(struct sockaddr); | 18 | socklen_t len=sizeof(struct sockaddr); |
19 | char buffer[128]; | 19 | char buffer[128]; |
20 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 20 | FILE *fp=stdin; /* Will be replaced with sniffer */ |
21 | fd_set rset; | 21 | fd_set rset; |
22 | 22 | ||
23 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 23 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
24 | 24 | ||
25 | /* Setup socket for incoming commands */ | 25 | /* Setup socket for incoming commands */ |
26 | if(!commsock(&sock)) | 26 | if(!commsock(&sock)) |
27 | return 0; | 27 | return 0; |
28 | 28 | ||
29 | log_info("Set up socket '%d' for GUI communication", sock); | 29 | log_info("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 | log_info("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 | log_err("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 | log_err("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 | log_info("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 | commstring(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 | log_err("Cannot read from stdin: %s", strerror(errno)); |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | log_info("Sending command to '%s': %s", GUIADDR, buffer); | ||
72 | 73 | ||
73 | /* Send string to GUI */ | 74 | /* Send string to GUI */ |
74 | sendgui("%d: %s", 1234, buffer); | 75 | sendgui("%d: %s", 1234, buffer); |
75 | 76 | ||
76 | } | 77 | } |
77 | 78 | ||
78 | } | 79 | } |
79 | 80 | ||
80 | close(sock); | 81 | close(sock); |
81 | return 0; | 82 | return 0; |
82 | } | 83 | } |
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.cc b/noncore/net/wellenreiter/daemon/source/sendgui.cc index 48ad5b8..9e57094 100644 --- a/noncore/net/wellenreiter/daemon/source/sendgui.cc +++ b/noncore/net/wellenreiter/daemon/source/sendgui.cc | |||
@@ -1,75 +1,42 @@ | |||
1 | /* | 1 | /* |
2 | * Send string to GUI | 2 | * Send string to GUI |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "config.hh" | 7 | #include "config.hh" |
8 | #include "sendgui.hh" | 8 | #include "sendgui.hh" |
9 | #include "log.hh" | 9 | #include "log.hh" |
10 | 10 | ||
11 | /* Simple dummy for alarm timer */ | ||
12 | static void alarmdummy(int signo) | ||
13 | { | ||
14 | alarm (0); | ||
15 | } | ||
16 | |||
17 | /* Connect to given IP on given port */ | ||
18 | int connect_server(int *sock, unsigned int ipaddr, int port) | ||
19 | { | ||
20 | struct sockaddr_in saddr; | ||
21 | int retval=0; | ||
22 | |||
23 | *sock = socket (PF_INET, SOCK_STREAM, 0); | ||
24 | saddr.sin_family = PF_INET; | ||
25 | saddr.sin_port = htons (port); | ||
26 | saddr.sin_addr.s_addr = ipaddr; | ||
27 | |||
28 | signal (SIGALRM, alarmdummy); | ||
29 | siginterrupt (SIGALRM, 1); | ||
30 | |||
31 | alarm(5); | ||
32 | retval=connect (*sock, (struct sockaddr *) &saddr, sizeof (saddr)); | ||
33 | alarm(0); | ||
34 | |||
35 | if(retval < 0) | ||
36 | { | ||
37 | close (*sock); | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | return 1; | ||
42 | } | ||
43 | |||
44 | /* Send a string to the GUI */ | 11 | /* Send a string to the GUI */ |
45 | int sendgui(const char *string, ...) | 12 | int sendgui(const char *string, ...) |
46 | { | 13 | { |
47 | int sock=0; | 14 | int sock=0; |
48 | char buffer[4096]; | 15 | char buffer[4096]; |
16 | struct sockaddr_in saddr; | ||
49 | va_list ap; | 17 | va_list ap; |
50 | 18 | ||
51 | /* Generate string */ | 19 | /* Generate string */ |
52 | memset(buffer, 0, sizeof(buffer)); | 20 | memset(buffer, 0, sizeof(buffer)); |
53 | va_start(ap, string); | 21 | va_start(ap, string); |
54 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); | 22 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); |
55 | va_end(ap); | 23 | va_end(ap); |
56 | 24 | ||
57 | if(!connect_server(&sock, inet_addr(GUIADDR), GUIPORT)) | 25 | /* Setup socket */ |
58 | { | 26 | sock = socket (AF_INET, SOCK_DGRAM, 0); |
59 | log_err("Connect to GUI at '%s' failed: %s", GUIADDR, strerror(errno)); | 27 | saddr.sin_family = AF_INET; |
60 | return 0; | 28 | saddr.sin_port = htons(GUIPORT); |
61 | } | 29 | saddr.sin_addr.s_addr = inet_addr(GUIADDR); |
62 | 30 | ||
63 | if(write(sock, buffer, sizeof(buffer)) < 0) | 31 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) |
64 | { | 32 | { |
65 | log_err("Cannot write to socket: %s", strerror(errno)); | 33 | log_err("Cannot write to socket: %s", strerror(errno)); |
66 | close(sock); | 34 | close(sock); |
67 | return 0; | 35 | return 0; |
68 | } | 36 | } |
69 | 37 | ||
70 | if(close(sock) < 0) | 38 | if(close(sock) < 0) |
71 | log_err("Cannot close socket: %s", strerror(errno)); | 39 | log_err("Cannot close socket: %s", strerror(errno)); |
72 | 40 | ||
73 | return 1; | 41 | return 1; |
74 | } | 42 | } |
75 | |||
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.hh b/noncore/net/wellenreiter/daemon/source/sendgui.hh index e083704..d9b3fcd 100644 --- a/noncore/net/wellenreiter/daemon/source/sendgui.hh +++ b/noncore/net/wellenreiter/daemon/source/sendgui.hh | |||
@@ -1,20 +1,19 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef SENDGUI_HH | 3 | #ifndef SENDGUI_HH |
4 | #define SENDGUI_HH | 4 | #define SENDGUI_HH |
5 | 5 | ||
6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
7 | #include <sys/socket.h> | 7 | #include <sys/socket.h> |
8 | #include <netinet/in.h> | 8 | #include <netinet/in.h> |
9 | #include <arpa/inet.h> | 9 | #include <arpa/inet.h> |
10 | #include <signal.h> | 10 | #include <signal.h> |
11 | #include <errno.h> | 11 | #include <errno.h> |
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | #include <stdlib.h> | 15 | #include <stdlib.h> |
16 | 16 | ||
17 | int connect_server(int *, unsigned int, int); | ||
18 | int sendgui(const char *string, ...); | 17 | int sendgui(const char *string, ...); |
19 | 18 | ||
20 | #endif /* SENDGUI_HH */ | 19 | #endif /* SENDGUI_HH */ |