author | max <max> | 2003-02-09 19:30:29 (UTC) |
---|---|---|
committer | max <max> | 2003-02-09 19:30:29 (UTC) |
commit | c0f8b347e790f042f0a14e6e58e67046a7e0b8e3 (patch) (unidiff) | |
tree | a5b4de3b986f37fa18a107b9000a8e7624889724 | |
parent | 39eed07684a2ae7d76aa61cdb00c8a4bcfc66ef0 (diff) | |
download | opie-c0f8b347e790f042f0a14e6e58e67046a7e0b8e3.zip opie-c0f8b347e790f042f0a14e6e58e67046a7e0b8e3.tar.gz opie-c0f8b347e790f042f0a14e6e58e67046a7e0b8e3.tar.bz2 |
Chanswitch
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 5cf4e97..8471efc 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,108 +1,108 @@ | |||
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 | 9 | ||
10 | /* should be parsed from cfg-file */ | 10 | /* should be parsed from cfg-file */ |
11 | #define MAXCHANNEL 13 | 11 | #define MAXCHANNEL 13 |
12 | #define CHANINTERVAL 100000 | 12 | #define CHANINTERVAL 700000 |
13 | 13 | ||
14 | /* Main function of wellenreiterd */ | 14 | /* Main function of wellenreiterd */ |
15 | int main(int argc, char **argv) | 15 | int main(int argc, char **argv) |
16 | { | 16 | { |
17 | int sock, maxfd, retval; | 17 | int sock, maxfd, retval; |
18 | char buffer[WL_SOCKBUF]; | 18 | char buffer[WL_SOCKBUF]; |
19 | struct pcap_pkthdr header; | 19 | struct pcap_pkthdr header; |
20 | struct sockaddr_in saddr; | 20 | struct sockaddr_in saddr; |
21 | pcap_t *handletopcap; | 21 | pcap_t *handletopcap; |
22 | wl_cardtype_t cardtype; | 22 | wl_cardtype_t cardtype; |
23 | pthread_t sub; | 23 | pthread_t sub; |
24 | const unsigned char *packet; | 24 | const unsigned char *packet; |
25 | 25 | ||
26 | fd_set rset; | 26 | fd_set rset; |
27 | 27 | ||
28 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 28 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
29 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | 29 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); |
30 | 30 | ||
31 | if(argc < 3) | 31 | if(argc < 3) |
32 | usage(); | 32 | usage(); |
33 | 33 | ||
34 | /* Set sniffer device */ | 34 | /* Set sniffer device */ |
35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); | 35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); |
36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); | 36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); |
37 | 37 | ||
38 | /* Set card type */ | 38 | /* Set card type */ |
39 | cardtype.type = atoi(argv[2]); | 39 | cardtype.type = atoi(argv[2]); |
40 | if(cardtype.type < 1 || cardtype.type > 4) | 40 | if(cardtype.type < 1 || cardtype.type > 4) |
41 | usage(); | 41 | usage(); |
42 | 42 | ||
43 | /* set card into monitor mode */ | 43 | /* set card into monitor mode */ |
44 | if(!card_into_monitormode(&handletopcap, cardtype.iface, | 44 | if(!card_into_monitormode(&handletopcap, cardtype.iface, |
45 | cardtype.type)) | 45 | cardtype.type)) |
46 | { | 46 | { |
47 | wl_logerr("Cannot initialize the wireless-card, aborting"); | 47 | wl_logerr("Cannot initialize the wireless-card, aborting"); |
48 | exit(EXIT_FAILURE); | 48 | exit(EXIT_FAILURE); |
49 | } | 49 | } |
50 | wl_loginfo("Set card into monitor mode"); | 50 | wl_loginfo("Set card into monitor mode"); |
51 | 51 | ||
52 | /* setup pcap */ | 52 | /* setup pcap */ |
53 | if((handletopcap = pcap_open_live(cardtype.iface, | 53 | if((handletopcap = pcap_open_live(cardtype.iface, |
54 | BUFSIZ, 1, 0, NULL)) == NULL) | 54 | BUFSIZ, 1, 0, NULL)) == NULL) |
55 | { | 55 | { |
56 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | 56 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); |
57 | exit(EXIT_FAILURE); | 57 | exit(EXIT_FAILURE); |
58 | } | 58 | } |
59 | 59 | ||
60 | #ifdef HAVE_PCAP_NONBLOCK | 60 | #ifdef HAVE_PCAP_NONBLOCK |
61 | pcap_setnonblock(handletopcap, 1, NULL); | 61 | pcap_setnonblock(handletopcap, 1, NULL); |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | /* Setup socket for incoming commands */ | 64 | /* Setup socket for incoming commands */ |
65 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) | 65 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) |
66 | { | 66 | { |
67 | wl_logerr("Cannot setup socket"); | 67 | wl_logerr("Cannot setup socket"); |
68 | exit(EXIT_FAILURE); | 68 | exit(EXIT_FAILURE); |
69 | } | 69 | } |
70 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 70 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
71 | 71 | ||
72 | /* Create channelswitching thread */ | 72 | /* Create channelswitching thread */ |
73 | if(pthread_create(&sub, NULL, channel_switcher, | 73 | if(pthread_create(&sub, NULL, channel_switcher, |
74 | (void *)&cardtype) != 0) | 74 | (void *)&cardtype) != 0) |
75 | { | 75 | { |
76 | wl_logerr("Cannot create thread: %s", strerror(errno)); | 76 | wl_logerr("Cannot create thread: %s", strerror(errno)); |
77 | close(sock); | 77 | close(sock); |
78 | exit(EXIT_FAILURE); | 78 | exit(EXIT_FAILURE); |
79 | } | 79 | } |
80 | if(pthread_detach(sub)) | 80 | if(pthread_detach(sub)) |
81 | { | 81 | { |
82 | wl_logerr("Error detaching thread"); | 82 | wl_logerr("Error detaching thread"); |
83 | close(sock); | 83 | close(sock); |
84 | pthread_exit((pthread_t *)sub); | 84 | pthread_exit((pthread_t *)sub); |
85 | exit(EXIT_FAILURE); | 85 | exit(EXIT_FAILURE); |
86 | } | 86 | } |
87 | wl_loginfo("Created and detached channel switching thread"); | 87 | wl_loginfo("Created and detached channel switching thread"); |
88 | 88 | ||
89 | FD_ZERO(&rset); | 89 | FD_ZERO(&rset); |
90 | 90 | ||
91 | /* Start main loop */ | 91 | /* Start main loop */ |
92 | wl_loginfo("Starting main loop"); | 92 | wl_loginfo("Starting main loop"); |
93 | while(1) | 93 | while(1) |
94 | { | 94 | { |
95 | 95 | ||
96 | FD_SET(sock, &rset); | 96 | FD_SET(sock, &rset); |
97 | FD_SET(pcap_fileno(handletopcap), &rset); | 97 | FD_SET(pcap_fileno(handletopcap), &rset); |
98 | 98 | ||
99 | /* maxfd = biggest filefd */ | 99 | /* maxfd = biggest filefd */ |
100 | maxfd = (sock > pcap_fileno(handletopcap) ? | 100 | maxfd = (sock > pcap_fileno(handletopcap) ? |
101 | sock + 1 : pcap_fileno(handletopcap)) + 1; | 101 | sock + 1 : pcap_fileno(handletopcap)) + 1; |
102 | 102 | ||
103 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 103 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
104 | { | 104 | { |
105 | wl_logerr("Error calling select: %s", strerror(errno)); | 105 | wl_logerr("Error calling select: %s", strerror(errno)); |
106 | break; | 106 | break; |
107 | } | 107 | } |
108 | 108 | ||