-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 @@ | |||
1 | /* | 1 | /* |
2 | * Startup functions of wellenreiter | 2 | * Startup functions of wellenreiter |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "config.hh" | 7 | #include "config.hh" |
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | #include "cardmode.hh" | 9 | #include "cardmode.hh" |
10 | #include "sniffer.hh" | 10 | #include "sniffer.hh" |
11 | 11 | ||
12 | /* Main function of wellenreiterd */ | 12 | /* Main function of wellenreiterd */ |
13 | int main(int argc, char **argv) | 13 | int main(int argc, char **argv) |
14 | { | 14 | { |
15 | int sock, maxfd; | 15 | int sock, maxfd, retval; |
16 | struct sockaddr_in *cliaddr; | ||
17 | socklen_t len=sizeof(struct sockaddr); | ||
18 | char buffer[128]; | 16 | char buffer[128]; |
19 | pcap_t *handletopcap; /* The handle to the libpcap */ | 17 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | 18 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ |
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | 19 | struct pcap_pkthdr header; /* The packet header from pcap*/ |
22 | const u_char *packet; /* The actual packet content*/ | 20 | const u_char *packet; /* The actual packet content*/ |
23 | 21 | ||
24 | fd_set rset; | 22 | fd_set rset; |
25 | 23 | ||
26 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 24 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
27 | 25 | ||
26 | #if 0 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | 27 | /* will be replaced soon, just for max because max is lazy :-) */ |
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | 28 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) |
30 | { | 29 | { |
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | 30 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); |
32 | exit(-1); | 31 | exit(-1); |
33 | } | 32 | } |
33 | #endif | ||
34 | 34 | ||
35 | /* opening the pcap for sniffing */ | 35 | /* opening the pcap for sniffing */ |
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | 36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); |
37 | #ifdef HAVE_PCAP_NONBLOCK | 37 | #ifdef HAVE_PCAP_NONBLOCK |
38 | pcap_setnonblock(handletopcap, 1, errstr); | 38 | pcap_setnonblock(handletopcap, 1, errstr); |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) | 42 | if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) |
43 | { | 43 | { |
44 | wl_logerr("Cannot setup socket"); | 44 | wl_logerr("Cannot setup socket"); |
45 | exit(-1); | 45 | exit(-1); |
46 | } | 46 | } |
47 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 47 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
48 | 48 | ||
49 | FD_ZERO(&rset); | 49 | FD_ZERO(&rset); |
50 | 50 | ||
51 | /* Start main loop */ | 51 | /* Start main loop */ |
52 | wl_loginfo("Starting main loop"); | 52 | wl_loginfo("Starting main loop"); |
53 | while(1) | 53 | while(1) |
54 | { | 54 | { |
55 | 55 | ||
56 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
57 | FD_SET(pcap_fileno(handletopcap), &rset); | 57 | // FD_SET(pcap_fileno(handletopcap), &rset); |
58 | maxfd=sock + pcap_fileno(handletopcap) + 1; | 58 | // maxfd=sock + pcap_fileno(handletopcap) + 1; |
59 | maxfd=sock + 1; | ||
59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 60 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
60 | { | 61 | { |
61 | wl_logerr("Error calling select: %s", strerror(errno)); | 62 | wl_logerr("Error calling select: %s", strerror(errno)); |
62 | break; | 63 | break; |
63 | } | 64 | } |
64 | 65 | ||
65 | /* Got data on local socket from GUI */ | 66 | /* Got data on local socket from GUI */ |
66 | if(FD_ISSET(sock, &rset)) | 67 | if(FD_ISSET(sock, &rset)) |
67 | { | 68 | { |
68 | memset(buffer, 0, sizeof(buffer)); | 69 | |
69 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | 70 | if((retval=recvcomm(&sock, buffer, sizeof(buffer))) < 0) |
70 | { | 71 | { |
71 | wl_logerr("Cannot read from socket: %s", strerror(errno)); | 72 | wl_logerr("Error trying to read: %s", strerror(errno)); |
72 | break; | 73 | break; |
73 | } | 74 | } |
74 | wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | 75 | else |
75 | 76 | { | |
76 | /* will be passed to analyze function */ | 77 | switch(retval) |
77 | fprintf(stderr, "Received command: %s\n", buffer); | 78 | { |
78 | 79 | case 98: | |
79 | } | 80 | { |
80 | 81 | wl_loginfo("Received STARTSNIFF command"); | |
82 | break; | ||
83 | }; | ||
84 | case 99: | ||
85 | { | ||
86 | wl_loginfo("Received STOPSNIFF command"); | ||
87 | break; | ||
88 | }; | ||
89 | default: | ||
90 | { | ||
91 | wl_logerr("Received unknown command: %d", retval); | ||
92 | break; | ||
93 | }; | ||
94 | } | ||
95 | } | ||
96 | } /* FD_ISSET */ | ||
97 | |||
98 | #if 0 | ||
81 | /* Pcap stuff */ | 99 | /* Pcap stuff */ |
82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 100 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
83 | { | 101 | { |
84 | 102 | ||
85 | /* Grab one single packet */ | 103 | /* Grab one single packet */ |
86 | packet = pcap_next(handletopcap, &header); | 104 | packet = pcap_next(handletopcap, &header); |
87 | 105 | ||
88 | /* process the packet */ | 106 | /* process the packet */ |
89 | process_packets(NULL,&header,*&packet); | 107 | process_packets(NULL,&header,*&packet); |
90 | |||
91 | } | 108 | } |
109 | #endif | ||
92 | } | 110 | } |
93 | close(sock); | 111 | close(sock); |
94 | exit(0); | 112 | exit(0); |
95 | } | 113 | } |
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 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef DAEMON_HH | 3 | #ifndef DAEMON_HH |
4 | #define DAEMON_HH | 4 | #define DAEMON_HH |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <sys/types.h> | 8 | #include <sys/types.h> |
9 | #include <sys/time.h> | 9 | #include <sys/time.h> |
10 | #include <sys/socket.h> | 10 | #include <sys/socket.h> |
11 | #include <netinet/in.h> | 11 | #include <netinet/in.h> |
12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | #include "../../libwellenreiter/source/sock.hh" | 16 | #include "../../libwellenreiter/source/sock.hh" |
17 | #include "../../libwellenreiter/source/log.hh" | 17 | #include "../../libwellenreiter/source/log.hh" |
18 | #include "../../libwellenreiter/source/proto.hh" | ||
19 | |||
18 | 20 | ||
19 | #endif /* DAEMON_HH */ | 21 | #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,49 +1,49 @@ | |||
1 | /* $Id */ | 1 | /* $Id$ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 | 3 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 |
4 | *The Regents of the University of California. All rights reserved. | 4 | *The Regents of the University of California. All rights reserved. |
5 | * | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that: (1) source code distributions | 7 | * modification, are permitted provided that: (1) source code distributions |
8 | * retain the above copyright notice and this paragraph in its entirety, (2) | 8 | * retain the above copyright notice and this paragraph in its entirety, (2) |
9 | * distributions including binary code include the above copyright notice and | 9 | * distributions including binary code include the above copyright notice and |
10 | * this paragraph in its entirety in the documentation or other materials | 10 | * this paragraph in its entirety in the documentation or other materials |
11 | * provided with the distribution, and (3) all advertising materials mentioning | 11 | * provided with the distribution, and (3) all advertising materials mentioning |
12 | * features or use of this software display the following acknowledgement: | 12 | * features or use of this software display the following acknowledgement: |
13 | * ``This product includes software developed by the University of California, | 13 | * ``This product includes software developed by the University of California, |
14 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of | 14 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
15 | * the University nor the names of its contributors may be used to endorse | 15 | * the University nor the names of its contributors may be used to endorse |
16 | * or promote products derived from this software without specific prior | 16 | * or promote products derived from this software without specific prior |
17 | * written permission. | 17 | * written permission. |
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED | 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
19 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | 19 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
21 | */ | 21 | */ |
22 | /* Network to host order macros */ | 22 | /* Network to host order macros */ |
23 | 23 | ||
24 | #ifndef EXTRACT_HH | 24 | #ifndef EXTRACT_HH |
25 | #define EXTRACT_HH | 25 | #define EXTRACT_HH |
26 | 26 | ||
27 | #ifdef LBL_ALIGN | 27 | #ifdef LBL_ALIGN |
28 | #define EXTRACT_16BITS(p) \ | 28 | #define EXTRACT_16BITS(p) \ |
29 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ | 29 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ |
30 | (u_int16_t)*((const u_int8_t *)(p) + 1))) | 30 | (u_int16_t)*((const u_int8_t *)(p) + 1))) |
31 | #define EXTRACT_32BITS(p) \ | 31 | #define EXTRACT_32BITS(p) \ |
32 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ | 32 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ |
33 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ | 33 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ |
34 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ | 34 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ |
35 | (u_int32_t)*((const u_int8_t *)(p) + 3))) | 35 | (u_int32_t)*((const u_int8_t *)(p) + 3))) |
36 | #else | 36 | #else |
37 | #define EXTRACT_16BITS(p) \ | 37 | #define EXTRACT_16BITS(p) \ |
38 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) | 38 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) |
39 | #define EXTRACT_32BITS(p) \ | 39 | #define EXTRACT_32BITS(p) \ |
40 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) | 40 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #define EXTRACT_24BITS(p) \ | 43 | #define EXTRACT_24BITS(p) \ |
44 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ | 44 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ |
45 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 45 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
46 | (u_int32_t)*((const u_int8_t *)(p) + 2))) | 46 | (u_int32_t)*((const u_int8_t *)(p) + 2))) |
47 | 47 | ||
48 | /* Little endian protocol host order macros */ | 48 | /* Little endian protocol host order macros */ |
49 | 49 | ||
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 @@ | |||
1 | /* | ||
2 | * Send string to GUI | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "config.hh" | ||
8 | #include "sendgui.hh" | ||
9 | #include "log.hh" | ||
10 | |||
11 | /* Send a string to the GUI */ | ||
12 | int sendgui(const char *string, ...) | ||
13 | { | ||
14 | int sock=0; | ||
15 | char buffer[4096]; | ||
16 | struct sockaddr_in saddr; | ||
17 | va_list ap; | ||
18 | |||
19 | /* Generate string */ | ||
20 | memset(buffer, 0, sizeof(buffer)); | ||
21 | va_start(ap, string); | ||
22 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); | ||
23 | va_end(ap); | ||
24 | |||
25 | /* Setup socket */ | ||
26 | sock = socket (AF_INET, SOCK_DGRAM, 0); | ||
27 | saddr.sin_family = AF_INET; | ||
28 | saddr.sin_port = htons(GUIPORT); | ||
29 | saddr.sin_addr.s_addr = inet_addr(GUIADDR); | ||
30 | |||
31 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) | ||
32 | { | ||
33 | log_err("Cannot write to socket: %s", strerror(errno)); | ||
34 | close(sock); | ||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | if(close(sock) < 0) | ||
39 | log_err("Cannot close socket: %s", strerror(errno)); | ||
40 | |||
41 | return 1; | ||
42 | } | ||
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 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #ifndef SENDGUI_HH | ||
4 | #define SENDGUI_HH | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <sys/socket.h> | ||
8 | #include <netinet/in.h> | ||
9 | #include <arpa/inet.h> | ||
10 | #include <signal.h> | ||
11 | #include <errno.h> | ||
12 | #include <string.h> | ||
13 | #include <stdio.h> | ||
14 | #include <unistd.h> | ||
15 | #include <stdlib.h> | ||
16 | |||
17 | int sendgui(const char *string, ...); | ||
18 | |||
19 | #endif /* SENDGUI_HH */ | ||