-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 54 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.hh | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/extract.hh | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sendgui.cc | 42 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sendgui.hh | 19 |
5 files changed, 39 insertions, 80 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 1f9e98a..a2e1f96 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc @@ -1,95 +1,113 @@ /* * Startup functions of wellenreiter * * $Id$ */ #include "config.hh" #include "daemon.hh" #include "cardmode.hh" #include "sniffer.hh" /* Main function of wellenreiterd */ int main(int argc, char **argv) { - int sock, maxfd; - struct sockaddr_in *cliaddr; - socklen_t len=sizeof(struct sockaddr); + int sock, maxfd, retval; char buffer[128]; pcap_t *handletopcap; /* The handle to the libpcap */ char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ struct pcap_pkthdr header; /* The packet header from pcap*/ const u_char *packet; /* The actual packet content*/ fd_set rset; fprintf(stderr, "wellenreiterd %s\n\n", VERSION); +#if 0 /* will be replaced soon, just for max because max is lazy :-) */ if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) { fprintf(stderr, "Cannot set card into mon mode, aborting\n"); exit(-1); } +#endif /* opening the pcap for sniffing */ handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); #ifdef HAVE_PCAP_NONBLOCK pcap_setnonblock(handletopcap, 1, errstr); #endif /* Setup socket for incoming commands */ if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) { wl_logerr("Cannot setup socket"); exit(-1); - } + } wl_loginfo("Set up socket '%d' for GUI communication", sock); FD_ZERO(&rset); /* Start main loop */ wl_loginfo("Starting main loop"); while(1) { FD_SET(sock, &rset); - FD_SET(pcap_fileno(handletopcap), &rset); - maxfd=sock + pcap_fileno(handletopcap) + 1; + // FD_SET(pcap_fileno(handletopcap), &rset); + // maxfd=sock + pcap_fileno(handletopcap) + 1; + maxfd=sock + 1; if(select(maxfd, &rset, NULL, NULL, NULL) < 0) { wl_logerr("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) + + if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0) { - wl_logerr("Cannot read from socket: %s", strerror(errno)); - break; + wl_logerr("Error trying to read: %s", strerror(errno)); + break; } - wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); - - /* will be passed to analyze function */ - fprintf(stderr, "Received command: %s\n", buffer); - - } - + else + { + switch(retval) + { + case 98: + { + wl_loginfo("Received STARTSNIFF command"); + break; + }; + case 99: + { + wl_loginfo("Received STOPSNIFF command"); + break; + }; + default: + { + wl_logerr("Received unknown command: %d", retval); + break; + }; + } + } + } /* FD_ISSET */ + +#if 0 /* Pcap stuff */ if(FD_ISSET(pcap_fileno(handletopcap), &rset)) { /* Grab one single packet */ packet = pcap_next(handletopcap, &header); /* process the packet */ process_packets(NULL,&header,*&packet); - } +#endif } close(sock); exit(0); } diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh index a9a97ac..12ba57e 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.hh +++ b/noncore/net/wellenreiter/daemon/source/daemon.hh @@ -1,19 +1,21 @@ /* $Id$ */ #ifndef DAEMON_HH #define DAEMON_HH #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h> #include "../../libwellenreiter/source/sock.hh" #include "../../libwellenreiter/source/log.hh" +#include "../../libwellenreiter/source/proto.hh" + #endif /* DAEMON_HH */ diff --git a/noncore/net/wellenreiter/daemon/source/extract.hh b/noncore/net/wellenreiter/daemon/source/extract.hh index 21dcffa..e900cfa 100644 --- a/noncore/net/wellenreiter/daemon/source/extract.hh +++ b/noncore/net/wellenreiter/daemon/source/extract.hh @@ -1,60 +1,60 @@ -/* $Id */ +/* $Id$ */ /* * Copyright (c) 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Network to host order macros */ #ifndef EXTRACT_HH #define EXTRACT_HH #ifdef LBL_ALIGN #define EXTRACT_16BITS(p) \ ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ (u_int16_t)*((const u_int8_t *)(p) + 1))) #define EXTRACT_32BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 3))) #else #define EXTRACT_16BITS(p) \ ((u_int16_t)ntohs(*(const u_int16_t *)(p))) #define EXTRACT_32BITS(p) \ ((u_int32_t)ntohl(*(const u_int32_t *)(p))) #endif #define EXTRACT_24BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 2))) /* Little endian protocol host order macros */ #define EXTRACT_LE_8BITS(p) (*(p)) #define EXTRACT_LE_16BITS(p) \ ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int16_t)*((const u_int8_t *)(p) + 0))) #define EXTRACT_LE_32BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 0))) #endif /* EXTRACT_HH */ diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.cc b/noncore/net/wellenreiter/daemon/source/sendgui.cc deleted file mode 100644 index 9e57094..0000000 --- a/noncore/net/wellenreiter/daemon/source/sendgui.cc +++ b/dev/null @@ -1,42 +0,0 @@ -/* - * Send string to GUI - * - * $Id$ - */ - -#include "config.hh" -#include "sendgui.hh" -#include "log.hh" - -/* 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); - - /* 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(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 deleted file mode 100644 index d9b3fcd..0000000 --- a/noncore/net/wellenreiter/daemon/source/sendgui.hh +++ b/dev/null @@ -1,19 +0,0 @@ -/* $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 sendgui(const char *string, ...); - -#endif /* SENDGUI_HH */ |