channel-switch: use sys/ioctl.h instead of stropts.h
[rofl0r-MacGeiger.git] / channel-switch.c
blob81327edc13d2f9ef91024c552b69321fc7485bc1
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/socket.h>
4 #include <net/if.h>
5 #include <sys/ioctl.h>
6 #include <unistd.h>
7 #include "wireless-lite.h"
9 /* returns 0 on success. */
10 int set_channel(const char* iface, int channel) {
11 int s;
12 if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
13 perror("socket");
14 return 1;
17 struct iwreq req = {.u.freq.m = channel, .u.freq.flags = IW_FREQ_FIXED};
18 snprintf(req.ifr_name, IFNAMSIZ, "%s", iface);
20 int ret;
21 if((ret = ioctl(s, SIOCSIWFREQ, &req) < 0)) {
22 #ifndef LIBRARY_CODE
23 perror("ioctl");
24 #endif
26 close(s);
27 return ret;
30 #ifndef LIBRARY_CODE
31 static int usage(char* argv0) {
32 dprintf(2, "usage: %s interface channel\n", argv0);
33 return 1;
36 int main(int argc, char** argv) {
37 if(argc != 3) return usage(argv[0]);
38 return set_channel(argv[1], atoi(argv[2]));
40 #endif