summaryrefslogtreecommitdiff
authormjm <mjm>2002-11-13 21:57:18 (UTC)
committer mjm <mjm>2002-11-13 21:57:18 (UTC)
commit9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9 (patch) (unidiff)
tree427d7e9a07573d295eeabf926d1664ec955331fd
parentd3301ad9a74fdf693551bd70bc3cf34b311eaa49 (diff)
downloadopie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.zip
opie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.tar.gz
opie-9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9.tar.bz2
sendgui.cc is now udp based
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc1
-rw-r--r--noncore/net/wellenreiter/daemon/source/sendgui.cc47
-rw-r--r--noncore/net/wellenreiter/daemon/source/sendgui.hh1
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
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
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);
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
@@ -8,44 +8,12 @@
8#include "sendgui.hh" 8#include "sendgui.hh"
9#include "log.hh" 9#include "log.hh"
10 10
11/* Simple dummy for alarm timer */
12static void alarmdummy(int signo)
13{
14 alarm (0);
15}
16
17/* Connect to given IP on given port */
18int 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 */
45int sendgui(const char *string, ...) 12int 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 */
@@ -54,13 +22,13 @@ int sendgui(const char *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);
@@ -72,4 +40,3 @@ int sendgui(const char *string, ...)
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
@@ -14,7 +14,6 @@
14#include <unistd.h> 14#include <unistd.h>
15#include <stdlib.h> 15#include <stdlib.h>
16 16
17int connect_server(int *, unsigned int, int);
18int sendgui(const char *string, ...); 17int sendgui(const char *string, ...);
19 18
20#endif /* SENDGUI_HH */ 19#endif /* SENDGUI_HH */