1 /*
2     This file is part of Kismet
3 
4     Kismet is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     Kismet is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with Kismet; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19 #ifndef __IFCONTROL_H__
20 #define __IFCONTROL_H__
21 
22 #include "config.h"
23 
24 #include <errno.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 
29 #include <sys/socket.h>
30 
31 #ifdef SYS_LINUX
32 #include <asm/types.h>
33 #include <linux/if.h>
34 #else
35 #include <net/if.h>
36 #endif
37 
38 #ifndef SYS_CYGWIN
39 #include <net/if_arp.h>
40 #include <sys/ioctl.h>
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
43 #include <arpa/inet.h>
44 #endif
45 
46 #ifdef SYS_NETBSD
47 #include <net80211/ieee80211.h>
48 #include <net80211/ieee80211_ioctl.h>
49 #endif
50 
51 #include "util.h"
52 
53 #if defined(SYS_LINUX) || defined(SYS_NETBSD) || defined(SYS_OPENBSD) || \
54 	defined(SYS_FREEBSD) || defined(SYS_DARWIN)
55 int Ifconfig_Set_Flags(const char *in_dev, char *errstr, int flags);
56 int Ifconfig_Delta_Flags(const char *in_dev, char *errstr, int flags);
57 int Ifconfig_Get_Flags(const char *in_dev, char *errstr, int *flags);
58 #endif
59 
60 #ifdef SYS_LINUX
61 int Ifconfig_Get_Hwaddr(const char *in_dev, char *errstr, uint8_t *ret_hwaddr);
62 int Ifconfig_Set_Hwaddr(const char *in_dev, char *errstr, uint8_t *in_hwaddr);
63 int Ifconfig_Set_MTU(const char *in_dev, char *errstr, uint16_t in_mtu);
64 
65 // Definitions gratuitiously yoinked from ethtool-2 for getting
66 // driver info
67 #define ETHTOOL_BUSINFO_LEN	32
68 struct ethtool_drvinfo {
69 	uint32_t cmd;
70 	char driver[32]; // Driver short name
71 	char version[32]; // Driver version
72 	char fw_version[32]; // Driver firmware version
73 	// We don't really care about anything below here but we need it
74 	// anyhow.
75 	char bus_info[ETHTOOL_BUSINFO_LEN]; // Bus info
76 	char reserved1[32];
77 	char reserved2[16];
78 	uint32_t n_stats; // Number of ETHTOOL_GSTATS
79 	uint32_t testinfo_len;
80 	uint32_t eedump_len; // Size of ETHTOOL_GEEPROM
81 	uint32_t regdump_len;
82 };
83 
84 #ifndef ETHTOOL_GDRVINFO
85 #define ETHTOOL_GDRVINFO	0x00000003
86 #endif
87 
88 #ifndef SIOCETHTOOL
89 #define SIOCETHTOOL			0x8946
90 #endif
91 
92 // Get the ethtool info
93 int Linux_GetDrvInfo(const char *in_dev, char *errstr, struct ethtool_drvinfo *info);
94 string Linux_GetSysDrv(const char *in_dev);
95 int Linux_GetSysDrvAttr(const char *in_dev, const char *in_attr);
96 int Ifconfig_Get_Hwaddr(const char *in_dev, char *errstr, uint8_t *ret_hwaddr);
97 int Ifconfig_Set_Hwaddr(const char *in_dev, char *errstr, uint8_t *in_hwaddr);
98 int Ifconfig_Set_MTU(const char *in_dev, char *errstr, uint16_t in_mtu);
99 int Ifconfig_Set_IP(const char *in_dev, char *errstr, const char *ip);
100 int Ifconfig_Set_Netmask(const char *in_dev, char *errstr, const char *netmask);
101 #endif
102 
103 #endif
104