-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
if_helper.c
65 lines (58 loc) · 1.69 KB
/
if_helper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "if_helper.h"
// Either I'm blind, or libiw API documentation is very hard to find,
// so for now system() calls will have to do for configuring the
// wireless interface.
int if_up(char *name) {
char buf[128];
snprintf(buf, sizeof(buf), "ifconfig %s up", name);
int ret = system(buf);
if (ret != 0) {
printf("Could not bring up interface %s\n", name);
}
return ret;
}
int if_down(char *name) {
char buf[128];
snprintf(buf, sizeof(buf), "ifconfig %s down", name);
int ret = system(buf);
if (ret != 0) {
printf("Could not bring down interface %s\n", name);
}
return ret;
}
int if_mtu(char *name, int mtu) {
char buf[128];
snprintf(buf, sizeof(buf), "ifconfig %s mtu %d", name, mtu);
int ret = system(buf);
if (ret != 0) {
printf("Could not set MTU for interface %s\n", name);
}
return ret;
}
int if_enable_ibss(char *name) {
char buf[128];
snprintf(buf, sizeof(buf), "iw %s set type ibss", name);
int ret = system(buf);
if (ret != 0) {
printf("Could not enable IBSS on %s\n", name);
}
return ret;
}
int if_join_ibss(char *name, char *essid, int frequency) {
char buf[128];
snprintf(buf, sizeof(buf), "iw %s ibss join %s %d", name, essid, frequency);
int ret = system(buf);
if (ret != 0) {
printf("Interface %s failed enabling ESSID \"%s\" on frequency %d \n", name, essid, frequency);
}
return ret;
}
int if_promisc(char *name) {
char buf[128];
snprintf(buf, sizeof(buf), "ifconfig %s promisc", name);
int ret = system(buf);
if (ret != 0) {
printf("Could not put interface %s into promiscous mode\n", name);
}
return ret;
}