-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface_control.h
159 lines (133 loc) · 4.35 KB
/
interface_control.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __INTERFACE_CONTROL_H__
#define __INTERFACE_CONTROL_H__
#include "config.h"
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <net/if.h>
#ifndef SYS_CYGWIN
#include <net/if_arp.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#endif
#ifdef SYS_NETBSD
#include <net80211/ieee80211.h>
#include <net80211/ieee80211_ioctl.h>
#endif
#if defined(SYS_LINUX) || defined(SYS_NETBSD) || defined(SYS_OPENBSD) || \
defined(SYS_FREEBSD) || defined(SYS_DARWIN)
/* proxy for SIOCGIFFLAGS and SIOCSIFFLAGS
* delta_flags will fetch the current set of flags and add new ones to it
*
* Returns:
* 0 Success
* Others Failure, errno returned
*/
int ifconfig_set_flags(const char *in_dev, char *errstr, int flags);
int ifconfig_delta_flags(const char *in_dev, char *errstr, int flags);
int ifconfig_get_flags(const char *in_dev, char *errstr, int *flags);
/* Bring an interface up or down by setting up, running, and promisc
*
* Returns:
* 0 Success
* Others Failure, errno returned
*/
int ifconfig_interface_up(const char *in_dev, char *errstr);
int ifconfig_interface_down(const char *in_dev, char *errstr);
#endif
#ifdef SYS_LINUX
/* Linux-specific functions for setting hardware address and MTU */
/* Fetches the current HW address of the device and copies it to ret_hwaddr.
* ret_hwaddr must be allocated by the caller and be able to hold 6 bytes.
* Only the first 6 bytes of the interface will be copied.
*
* Errstr must be allocated by the caller and be able to hold STATUS_MAX characters.
*
* Returns:
* -1 Error
* 0 Success
*/
int ifconfig_get_hwaddr(const char *in_dev, char *errstr, uint8_t *ret_hwaddr);
/* Definitions from ethtool-2 */
#define ETHTOOL_BUSINFO_LEN 32
struct ethtool_drvinfo {
uint32_t cmd;
char driver[32]; // Driver short name
char version[32]; // Driver version
char fw_version[32]; // Driver firmware version
// We don't really care about anything below here but we need it
// anyhow.
char bus_info[ETHTOOL_BUSINFO_LEN]; // Bus info
char reserved1[32];
char reserved2[16];
uint32_t n_stats; // Number of ETHTOOL_GSTATS
uint32_t testinfo_len;
uint32_t eedump_len; // Size of ETHTOOL_GEEPROM
uint32_t regdump_len;
};
#ifndef ETHTOOL_GDRVINFO
#define ETHTOOL_GDRVINFO 0x00000003
#endif
#ifndef SIOCETHTOOL
#define SIOCETHTOOL 0x8946
#endif
/* Get driver info, placed in ethtool_drvinfo.
*
* errstr must be allocated by the caller and be able to hold STATUS_MAX characters
* ethtool_drvinfo must be allocated by the caller.
*
* Returns:
* -1 Error
* 1 Success
*/
int linux_getdrvinfo(const char *in_dev, char *errstr, struct ethtool_drvinfo *info);
/* Get driver by crawling the /sys filesystem.
*
* ret_driver must be allocated by the caller, and be able to hold at least 32
* characters.
*
* Returns:
* -1 Error
* 1 Success
*/
int linux_getsysdrv(const char *in_dev, char *ret_driver);
/* Get attribute (file in sys driver directory)
*
* Returns:
* 0 Attribute not available (or interface not found)
* 1 Attribute present
*/
int linux_getsysdrvattr(const char *in_dev, const char *in_attr);
#endif
#ifdef SYS_DARWIN
/* Fetches the current HW address of the device and copies it to ret_hwaddr.
* ret_hwaddr must be allocated by the caller and be able to hold 6 bytes.
* Only the first 6 bytes of the interface will be copied.
*
* Errstr must be allocated by the caller and be able to hold STATUS_MAX characters.
*
* Returns:
* -1 Error
* 0 Success
*/
int ifconfig_get_hwaddr(const char *in_dev, char *errstr, uint8_t *ret_hwaddr);
#endif
#endif