author | mjm <mjm> | 2002-11-13 21:57:18 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-11-13 21:57:18 (UTC) |
commit | 9c48a8f9d70af68b9e57a82cda637ad8c2abf5c9 (patch) (side-by-side diff) | |
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 @@ -1,82 +1,83 @@ /* * Startup functions of wellenreiter * * $Id$ */ #include "config.hh" #include "daemon.hh" #include "log.hh" #include "sendgui.hh" #include "getgui.hh" /* Main function of wellenreiterd */ int main(int argc, char **argv) { int sock, maxfd; struct sockaddr_in *cliaddr; socklen_t len=sizeof(struct sockaddr); char buffer[128]; FILE *fp=stdin; /* Will be replaced with sniffer */ fd_set rset; fprintf(stderr, "wellenreiterd %s\n\n", VERSION); /* Setup socket for incoming commands */ if(!commsock(&sock)) return 0; log_info("Set up socket '%d' for GUI communication", sock); FD_ZERO(&rset); /* Start main loop */ log_info("Starting main loop"); while(1) { FD_SET(sock, &rset); FD_SET(fileno(fp), &rset); maxfd=sock+fileno(fp)+1; if(select(maxfd, &rset, NULL, NULL, NULL) < 0) { log_err("Error calling select: %s", strerror(errno)); break; } /* Got data on local socket from GUI */ if(FD_ISSET(sock, &rset)) { memset(buffer, 0, sizeof(buffer)); if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) { log_err("Cannot read from socket: %s", strerror(errno)); break; } log_info("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); /* Pass string to analyze function */ commstring(buffer); } /* Will be replaced with sniffer ... later */ if(FD_ISSET(fileno(fp), &rset)) { memset(buffer, 0, sizeof(buffer)); if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) { log_err("Cannot read from stdin: %s", strerror(errno)); break; } + log_info("Sending command to '%s': %s", GUIADDR, buffer); /* Send string to GUI */ sendgui("%d: %s", 1234, buffer); } } close(sock); return 0; } 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 @@ /* * Send string to GUI * * $Id$ */ #include "config.hh" #include "sendgui.hh" #include "log.hh" -/* Simple dummy for alarm timer */ -static void alarmdummy(int signo) -{ - alarm (0); -} - -/* Connect to given IP on given port */ -int connect_server(int *sock, unsigned int ipaddr, int port) -{ - struct sockaddr_in saddr; - int retval=0; - - *sock = socket (PF_INET, SOCK_STREAM, 0); - saddr.sin_family = PF_INET; - saddr.sin_port = htons (port); - saddr.sin_addr.s_addr = ipaddr; - - signal (SIGALRM, alarmdummy); - siginterrupt (SIGALRM, 1); - - alarm(5); - retval=connect (*sock, (struct sockaddr *) &saddr, sizeof (saddr)); - alarm(0); - - if(retval < 0) - { - close (*sock); - return 0; - } - - return 1; -} - /* Send a string to the GUI */ int sendgui(const char *string, ...) { int sock=0; char buffer[4096]; + struct sockaddr_in saddr; va_list ap; /* Generate string */ memset(buffer, 0, sizeof(buffer)); va_start(ap, string); vsnprintf(buffer, sizeof(buffer)-1, string, ap); va_end(ap); - if(!connect_server(&sock, inet_addr(GUIADDR), GUIPORT)) - { - log_err("Connect to GUI at '%s' failed: %s", GUIADDR, strerror(errno)); - return 0; - } + /* Setup socket */ + sock = socket (AF_INET, SOCK_DGRAM, 0); + saddr.sin_family = AF_INET; + saddr.sin_port = htons(GUIPORT); + saddr.sin_addr.s_addr = inet_addr(GUIADDR); - if(write(sock, buffer, sizeof(buffer)) < 0) + if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { log_err("Cannot write to socket: %s", strerror(errno)); close(sock); return 0; } if(close(sock) < 0) log_err("Cannot close socket: %s", strerror(errno)); return 1; } - 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 @@ /* $Id$ */ #ifndef SENDGUI_HH #define SENDGUI_HH #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <signal.h> #include <errno.h> #include <string.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> -int connect_server(int *, unsigned int, int); int sendgui(const char *string, ...); #endif /* SENDGUI_HH */ |