summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/daemon/source/daemon.cc
Side-by-side diff
Diffstat (limited to 'noncore/net/wellenreiter/daemon/source/daemon.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc50
1 files changed, 32 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc
index b3a37b6..1f9e98a 100644
--- a/noncore/net/wellenreiter/daemon/source/daemon.cc
+++ b/noncore/net/wellenreiter/daemon/source/daemon.cc
@@ -6,20 +6,38 @@
#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, guiport=GUIPORT;
- char guihost[]="127.0.0.1";
+ int sock, maxfd;
struct sockaddr_in *cliaddr;
socklen_t len=sizeof(struct sockaddr);
char buffer[128];
- FILE *fp=stdin; /* Will be replaced with sniffer */
+ 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);
+ /* 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);
+ }
+
+ /* 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)
{
@@ -36,8 +54,8 @@ int main(int argc, char **argv)
{
FD_SET(sock, &rset);
- FD_SET(fileno(fp), &rset);
- maxfd=sock+fileno(fp)+1;
+ 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));
@@ -55,24 +73,20 @@ int main(int argc, char **argv)
}
wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer);
- /* Pass string to analyze function */
- // sendcomm(guihost, guiport, buffer);
+ /* will be passed to analyze function */
+ fprintf(stderr, "Received command: %s\n", buffer);
}
- /* Will be replaced with sniffer ... later */
- if(FD_ISSET(fileno(fp), &rset))
+ /* Pcap stuff */
+ if(FD_ISSET(pcap_fileno(handletopcap), &rset))
{
- memset(buffer, 0, sizeof(buffer));
- if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL)
- {
- wl_logerr("Cannot read from stdin: %s", strerror(errno));
- break;
- }
- wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer);
- /* Send string to GUI */
- sendcomm(guihost, guiport, "%d: %s", 1234, buffer);
+ /* Grab one single packet */
+ packet = pcap_next(handletopcap, &header);
+
+ /* process the packet */
+ process_packets(NULL,&header,*&packet);
}
}