This repository has been archived by the owner on Apr 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathifconfig.h
146 lines (118 loc) · 5.05 KB
/
ifconfig.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
///////////////////////////////////////////////////////////////////////////////
//
// ifconfig.h
// Network interface utility library declarations.
// Copyright (C) 2005-2013 Point Clark Networks
//
///////////////////////////////////////////////////////////////////////////////
//
// This program 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.
//
// This program 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
// this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef IFCONFIG_H
#define IFCONFIG_H
#define IF_DEBUG 0x0001
#define IF_FREE(p) free(p)
#define IF_MALLOC(n) malloc(n)
#define IF_STRDUP(p) strdup(p)
#define MAX_INTERFACES 1024
#define MAX_ERROR_STR 1024
#define PROC_NET_DEV "/proc/net/dev"
#define SYSCONF_NET_SCRIPTS "/etc/sysconfig/network-scripts"
#define inaddrr(x) (*(struct in_addr *) &ifr.x[sizeof(sa.sin_port)])
// Context handle
typedef struct IF_CTX_t
{
int sd;
char *last_error;
unsigned short flags;
char *interfaces[MAX_INTERFACES];
char *pppoe[MAX_INTERFACES];
} if_ctx;
// From ethtool...
struct ethtool_value
{
__uint32_t cmd;
__uint32_t data;
};
// From ethtool...
struct ethtool_cmd
{
__uint32_t cmd;
__uint32_t supported;
__uint32_t advertising;
__uint16_t speed;
__uint8_t duplex;
__uint8_t port;
__uint8_t phy_address;
__uint8_t transceiver;
__uint8_t autoneg;
__uint32_t maxtxpkt;
__uint32_t maxrxpkt;
__uint32_t reserved[4];
};
// Create a context and socket.
// Return a context handle or -1 on error.
if_ctx *if_init(void);
// Free context, close socket.
void if_free(if_ctx *p_ctx);
// Return version string
char *if_version(char *buffer, size_t size);
// Return 0 if interface exists, -1 otherwise.
int if_exists(if_ctx *p_ctx, const char *device);
// Retrieve an array of all interfaces.
// Return the number of interfaces found or -1 on error.
int if_list(if_ctx *p_ctx);
// Retrieve an array of all PPPoE interfaces.
// Return the number of interfaces found or -1 on error.
int if_list_pppoe(if_ctx *p_ctx);
// Is this a PPP device?
int if_isppp(if_ctx *p_ctx, const char *device);
// Store the string address of the given interface (device) in buffer.
// Return the length of the address string or -1 on error.
int if_get_address(if_ctx *p_ctx, const char *device, char *buffer, size_t size);
// Store the string address of the given interface (device) in buffer.
// Return the length of the address string or -1 on error.
int if_get_dst_address(if_ctx *p_ctx, const char *device, char *buffer, size_t size);
// Store the string address of the given interface netmask in buffer.
// Return the length of the address string or -1 on error.
int if_get_netmask(if_ctx *p_ctx, const char *device, char *buffer, size_t size);
// Store the string network address of the given ip and netmask in buffer.
// Return the length of the address string or -1 on error.
int if_get_network(if_ctx *p_ctx, const char *ip, const char *netmask, char *buffer, size_t size);
// Store the string prefix of the given netmask address in buffer.
// Return the length of the address string or -1 on error.
int if_get_prefix(if_ctx *p_ctx, const char *netmask, char *buffer, size_t size);
// Store the string address of the given interface broadcast in buffer.
// Return the length of the address string or -1 on error.
int if_get_broadcast(if_ctx *p_ctx, const char *device, char *buffer, size_t size);
// Store the string address of the given interface's hardwar address,
// (if there is one) in buffer.
// Return the length of the address string or -1 on error.
int if_get_hwaddress(if_ctx *p_ctx, const char *device, char *buffer, size_t size);
// Retrieve flags for device. Return -1 on error.
int if_get_flags(if_ctx *p_ctx, const char *device, short *flags);
// Retrieve MTU for device. Return -1 on error.
int if_get_mtu(if_ctx *p_ctx, const char *device, int *mtu);
// Retrieve metric for device. Return -1 on error.
int if_get_metric(if_ctx *p_ctx, const char *device, int *metric);
// Determine if the device has link (if supported).
// Return 0 for no link, 1 for link detect, and -1 on error.
int if_link_detect(if_ctx *p_ctx, const char *device);
// Store the device's negotiated link speed (if supported).
// Return 0 for no link, 1 for link detect, and -1 on error.
int if_get_speed(if_ctx *p_ctx, const char *device, unsigned short *speed);
#endif // IFCONFIG_H
// vi: expandtab shiftwidth=4 softtabstop=4 tabstop=4