2
* Copyright (c) 2006 Dell, Inc.
3
* by Matt Domsch <Matt_Domsch@dell.com>
4
* Licensed under the GNU General Public license, version 2.
5
* Copied from from net-tools-1.60, also under the GNU GPL v2,
6
* and modified for use here.
17
#define _PATH_PROCNET_DEV "/proc/net/dev"
19
static struct network_device *add_interface(struct libbiosdevname_state *state,
22
struct network_device *i;
23
i = malloc(sizeof(*i));
26
memset(i, 0, sizeof(*i));
27
INIT_LIST_HEAD(&i->node);
28
strncpy(i->kernel_name, name, sizeof(i->kernel_name));
29
list_add_tail(&i->node, &state->network_devices);
34
static char *get_name(char **namep, char *p)
44
if (*p == ':') { /* could be an alias */
45
char *dot = p, *dotname = name;
51
if (count == (IFNAMSIZ-1))
54
if (*p != ':') { /* it wasn't, backup */
65
if (count == (IFNAMSIZ-1))
74
int get_interfaces(struct libbiosdevname_state *state)
81
fh = fopen(_PATH_PROCNET_DEV, "r");
83
fprintf(stderr, "Error: cannot open %s (%s).\n",
84
_PATH_PROCNET_DEV, strerror(errno));
87
if (getline(&line, &linelen, fh) == -1 /* eat line */
88
|| getline(&line, &linelen, fh) == -1) {
94
while (getline(&line, &linelen, fh) != -1) {
96
s = get_name(&name, line);
97
add_interface(state, name);