-rw-r--r-- | noncore/net/wellenreiter/daemon/source/config.hh | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 35 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.hh | 2 |
3 files changed, 31 insertions, 8 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/config.hh b/noncore/net/wellenreiter/daemon/source/config.hh index 42c56da..cac9565 100644 --- a/noncore/net/wellenreiter/daemon/source/config.hh +++ b/noncore/net/wellenreiter/daemon/source/config.hh @@ -1,30 +1,28 @@ /* * * Global configuration for wellenreiter * * $Id$ * * Written by Martin J. Muench <mjm@codito.de> * */ #ifndef CONFIG_HH #define CONFIG_HH #define PROGNAME "wellenreiter" /* Name of program (for syslog et.al.) */ #define VERSION "0.2" /* Version of wellenreiter */ #define DAEMONADDR "127.0.0.1" #define DAEMONPORT 37772 /* Port of Daemon */ #define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */ #define GUIPORT 37773 /* Port of GUI, " " */ - /* Temporary cardmode stuff, will hopefully removed soon */ #define CARD_TYPE_CISCO 1 #define CARD_TYPE_NG 2 #define CARD_TYPE_HOSTAP 3 -#define SNIFFER_DEVICE "wlan0" #endif /* CONFIG_HH */ diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index cc72377..54f308a 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc @@ -1,73 +1,86 @@ /* * Startup functions of wellenreiter * * $Id$ */ #include "config.hh" #include "daemon.hh" /* Main function of wellenreiterd */ int main(int argc, char **argv) { - int sock, maxfd, retval; - char buffer[128]; + int sock, maxfd, retval, card_type; + char buffer[128], sniffer_device[5]; struct pcap_pkthdr header; 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(!card_into_monitormode(&handletopcap, SNIFFER_DEVICE, CARD_TYPE)) + if(argc < 3) + usage(); + + /* 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 set card into mon mode, aborting"); exit(-1); } wl_loginfo("Set card into monitor mode"); /////// following line will be moved to lib as soon as possible //////////// - if((handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 0, NULL)) == NULL) + if((handletopcap = pcap_open_live(sniffer_device, BUFSIZ, 1, 0, NULL)) == NULL) { wl_logerr("pcap_open_live() failed: %s", strerror(errno)); exit(-1); } #ifdef HAVE_PCAP_NONBLOCK pcap_setnonblock(handletopcap, 1, NULL); #endif /* getting the datalink type */ retval = pcap_datalink(handletopcap); if (retval != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ { - wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", SNIFFER_DEVICE); + wl_loginfo("Interface %s does not work in the correct 802.11 raw mode", sniffer_device); pcap_close(handletopcap); return 0; } - wl_loginfo("Your successfully listen on %s in 802.11 raw mode", SNIFFER_DEVICE); + wl_loginfo("Your successfully listen on %s in 802.11 raw mode", sniffer_device); //////////////////////////////////////// /* 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; if(select(maxfd, &rset, NULL, NULL, NULL) < 0) { wl_logerr("Error calling select: %s", strerror(errno)); @@ -96,24 +109,34 @@ int main(int argc, char **argv) break; default: wl_logerr("Received unknown command: %d", retval); break; } } } /* FD_ISSET */ /* Check pcap lib for packets */ if(FD_ISSET(pcap_fileno(handletopcap), &rset)) { /* Grab one single packet */ packet = pcap_next(handletopcap, &header); /* process the packet */ process_packets(&header,*&packet, GUIADDR, GUIPORT); } } /* while(1) */ close(sock); exit(0); } + +void usage(void) +{ + fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ + "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ + "\t<cardtype> = Cardtype:\t Cisco\t= 1\n" \ + "\t\t\t\tNG\t= 2\n" \ + "\t\t\t\tHOSTAP\t= 3\n"); + exit(-1); +} diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh index 09acf11..8d03b97 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.hh +++ b/noncore/net/wellenreiter/daemon/source/daemon.hh @@ -1,22 +1,24 @@ /* $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" #include "../../libwellenreiter/source/cardmode.hh" #include "../../libwellenreiter/source/sniff.hh" +void usage(void); + #endif /* DAEMON_HH */ |