author | mjm <mjm> | 2003-02-07 11:35:02 (UTC) |
---|---|---|
committer | mjm <mjm> | 2003-02-07 11:35:02 (UTC) |
commit | e92743832becd6dc8040e62e73c8ac3f7194f2d6 (patch) (side-by-side diff) | |
tree | 16c10598f92097f5900278c780196a30a42ab023 | |
parent | 9bbfe155d26fe42ecb31744de0525a1f854b7ca5 (diff) | |
download | opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.zip opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.tar.gz opie-e92743832becd6dc8040e62e73c8ac3f7194f2d6.tar.bz2 |
inserted temporary channel switching via alarm()
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 51c2194..d6e8f6b 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc @@ -1,39 +1,56 @@ /* * Startup functions of wellenreiter * * $Id$ */ #include "config.hh" #include "daemon.hh" +// temporary solution, will be removed soon +#define MAXCHANNEL 13 +char sniffer_device[6]; +int channel=0; +int timedout=1; + +static int chanswitch() +{ + if(channel >= MAXCHANNEL) + channel=1 + card_set_channel(sniffer_device, channel, card_type); + timedout=0; +} + /* Main function of wellenreiterd */ int main(int argc, char **argv) { int sock, maxfd, retval, card_type; - char buffer[WL_SOCKBUF], sniffer_device[6]; + char buffer[WL_SOCKBUF]; struct pcap_pkthdr header; struct sockaddr_in saddr; pcap_t *handletopcap; const unsigned char *packet; fd_set rset; fprintf(stderr, "wellenreiterd %s\n\n", VERSION); fprintf(stderr, "(c) 2002 by M-M-M\n\n"); if(argc < 3) usage(); + // removed soon, see above + SIGNAL(SIGALRM, chanswitch); + /* Set sniffer device */ memset(sniffer_device, 0, sizeof(sniffer_device)); strncpy(sniffer_device, (char *)argv[1], sizeof(sniffer_device) - 1); /* Set card type */ card_type = atoi(argv[2]); if(card_type < 1 || card_type > 3) usage(); if(!card_into_monitormode(&handletopcap, sniffer_device, card_type)) { wl_logerr("Cannot initialize the wireless-card, aborting"); @@ -63,38 +80,42 @@ int main(int argc, char **argv) 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); + // blah + timedout=1; + alarm(1); + /* socket or pcap handle bigger? Will be cleaned up, have to check pcap */ maxfd = (sock > pcap_fileno(handletopcap) ? sock : pcap_fileno(handletopcap)) + 1; - if(select(maxfd, &rset, NULL, NULL, NULL) < 0) + if(select(maxfd, &rset, NULL, NULL, NULL) < 0 && timedout) { wl_logerr("Error calling select: %s", strerror(errno)); break; } /* Got data on local socket from GUI */ if(FD_ISSET(sock, &rset)) { /* Receive data from socket */ - if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) + if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0 && timedout) { wl_logerr("Error trying to read: %s", strerror(errno)); break; } else { /* check type of packet and start function according to it */ switch(retval) { case 98: wl_loginfo("Received STARTSNIFF command"); break; |