summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c b/noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c
new file mode 100644
index 0000000..78f0299
--- a/dev/null
+++ b/noncore/net/wellenreiter/contrib/orinoco_hopper/orinoco_hopper.c
@@ -0,0 +1,118 @@
1/* orinoco_hopper.c
2 * orinoco wireless nic channel scanning utility
3 *
4 * By Snax <snax@shmoo.com>
5 * Copyright (c) 2002 Snax
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * For a copy of the GNU General Public License write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/time.h>
24#include <signal.h>
25#include <string.h>
26#include <sys/ioctl.h>
27#include <sys/socket.h>
28#include <linux/wireless.h>
29#include <unistd.h>
30#include <getopt.h>
31
32#ifndef SIOCIWFIRSTPRIV
33#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
34#endif
35
36void changeChannel(int);
37int setChannel( unsigned char channel );
38
39int max = 11;
40int mode = 2;
41char dev[32];
42
43void changeChannel(int x) {
44 static int chan = 0;
45 chan = (chan % max) + 1;
46 setChannel(chan);
47}
48
49int setChannel( unsigned char channel )
50{
51 int result = 0;
52 int fd;
53 struct iwreq ireq; //for Orinoco
54 int *ptr;
55
56 /* get a socket */
57 fd = socket(AF_INET, SOCK_STREAM, 0);
58
59 if ( fd == -1 ) {
60 return -1;
61 }
62 ptr = (int *) ireq.u.name;
63 ptr[0] = mode;
64 ptr[1] = channel;
65 strcpy(ireq.ifr_ifrn.ifrn_name, dev);
66 result = ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq);
67 close(fd);
68 return result;
69}
70
71void usage(char *cmd) {
72 fprintf(stderr,
73 "Usage: %s <iface> [-p] [-i <interval millisec>] [-n]\n -n = international channels\n -p = keep prism headers\n", cmd);
74 exit(1);
75}
76
77int main (int argc, char *argv[])
78{
79 struct itimerval tval;
80 int ms, r;
81
82 //this will be the channel scanning interval, currently 0.2 sec
83 struct timeval interval = {0, 200000};
84
85 if (argc < 2) usage(argv[0]);
86 strncpy(dev, argv[1], 32);
87 dev[31] = 0;
88
89 while (1) {
90 r = getopt(argc,argv,"i:np");
91 if (r < 0) break;
92 switch (r) {
93 case 'n':
94 max = 14;
95 break;
96 case 'p':
97 mode = 1;
98 break;
99 case 'i':
100 ms = atoi(optarg);
101 interval.tv_sec = ms / 1000;
102 interval.tv_usec = (ms % 1000) * 1000;
103 break;
104 default:
105 usage(argv[0]);
106 }
107 }
108
109 //this sets up the kchannel scanning stuff
110 signal(SIGALRM, changeChannel);
111 tval.it_interval = interval;
112 tval.it_value = interval;
113 setitimer(ITIMER_REAL, &tval, NULL);
114 while (1) pause();
115
116 return 0;
117}
118