. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / ip / ether_line.c
blobb88fa3403f447b476ab5c231e3066520c3afd4ba
1 /*
2 ** ETHER_LINE
3 **
4 ** This routine parses the array pointed to by "line" (which should be
5 ** from a file in the format of /etc/ethers) and returns in "eaddr" the
6 ** ethernet address at the start of the line and the corresponding host
7 ** name in "hostname". It assumes either tabs or spaces separate the
8 ** two. The buffer pointed to by "hostname" must be big enough to hold
9 ** the host name plus a NULL byte.
10 ** The function returns 0 on success and 1 on failure.
11 ** Arguments are assumed sensible. Null pointers will probably cause
12 ** exceptions.
13 ** Author: Gregory J. Sharp, July 1990
14 ** Adapted to MINIX: Philip Homburg, May 1992
17 #include <sys/types.h>
18 #include <ctype.h>
19 #include <stdlib.h>
20 #include <net/gen/ether.h>
21 #include <net/gen/if_ether.h>
23 int
24 ether_line(line, eaddr, hostname)
25 char * line;
26 struct ether_addr * eaddr;
27 char * hostname;
29 register int i;
30 register unsigned long val;
32 /* skip leading white space */
33 while (*line != '\n' && (*line == ' ' || *line == '\t'))
34 line++;
36 /* read the ethernet address */
37 for (i = 0; i < 5; i++)
39 val = (unsigned long) strtol(line, &line, 16);
40 if (val > 255 || *line++ != ':')
41 return 1;
42 eaddr->ea_addr[i] = val & 0xff;
44 val = (unsigned long) strtol(line, &line, 16);
45 if (val > 255 || (*line != ' ' && *line != '\t'))
46 return 1;
47 eaddr->ea_addr[i] = val & 0xff;
49 /* skip leading white space */
50 while (*line != '\n' && (*line == ' ' || *line == '\t'))
51 line++;
53 /* read in the hostname */
54 while (!isspace(*line))
55 *hostname++ = *line++;
56 *hostname = '\0';
57 return 0;