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.cc | 50 |
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 | |||
@@ -8,2 +8,4 @@ | |||
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | ||
9 | 11 | ||
@@ -12,4 +14,3 @@ int main(int argc, char **argv) | |||
12 | { | 14 | { |
13 | int sock, maxfd, guiport=GUIPORT; | 15 | int sock, maxfd; |
14 | char guihost[]="127.0.0.1"; | ||
15 | struct sockaddr_in *cliaddr; | 16 | struct sockaddr_in *cliaddr; |
@@ -17,3 +18,7 @@ int main(int argc, char **argv) | |||
17 | char buffer[128]; | 18 | char buffer[128]; |
18 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 19 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
22 | const u_char *packet; /* The actual packet content*/ | ||
23 | |||
19 | fd_set rset; | 24 | fd_set rset; |
@@ -22,2 +27,15 @@ int main(int argc, char **argv) | |||
22 | 27 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | ||
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
30 | { | ||
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | ||
32 | exit(-1); | ||
33 | } | ||
34 | |||
35 | /* opening the pcap for sniffing */ | ||
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | ||
37 | #ifdef HAVE_PCAP_NONBLOCK | ||
38 | pcap_setnonblock(handletopcap, 1, errstr); | ||
39 | #endif | ||
40 | |||
23 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
@@ -38,4 +56,4 @@ int main(int argc, char **argv) | |||
38 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
39 | FD_SET(fileno(fp), &rset); | 57 | FD_SET(pcap_fileno(handletopcap), &rset); |
40 | maxfd=sock+fileno(fp)+1; | 58 | maxfd=sock + pcap_fileno(handletopcap) + 1; |
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
@@ -57,4 +75,4 @@ int main(int argc, char **argv) | |||
57 | 75 | ||
58 | /* Pass string to analyze function */ | 76 | /* will be passed to analyze function */ |
59 | // sendcomm(guihost, guiport, buffer); | 77 | fprintf(stderr, "Received command: %s\n", buffer); |
60 | 78 | ||
@@ -62,15 +80,11 @@ int main(int argc, char **argv) | |||
62 | 80 | ||
63 | /* Will be replaced with sniffer ... later */ | 81 | /* Pcap stuff */ |
64 | if(FD_ISSET(fileno(fp), &rset)) | 82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
65 | { | 83 | { |
66 | memset(buffer, 0, sizeof(buffer)); | ||
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | ||
68 | { | ||
69 | wl_logerr("Cannot read from stdin: %s", strerror(errno)); | ||
70 | break; | ||
71 | } | ||
72 | wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer); | ||
73 | 84 | ||
74 | /* Send string to GUI */ | 85 | /* Grab one single packet */ |
75 | sendcomm(guihost, guiport, "%d: %s", 1234, buffer); | 86 | packet = pcap_next(handletopcap, &header); |
87 | |||
88 | /* process the packet */ | ||
89 | process_packets(NULL,&header,*&packet); | ||
76 | 90 | ||