Repository navigation
Expand file tree
/
Copy pathether_line.c
More file actions
58 lines (52 loc) · 1.55 KB
/
Copy pathether_line.c
File metadata and controls
58 lines (52 loc) · 1.55 KB
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
/*
** ETHER_LINE
**
** This routine parses the array pointed to by "line" (which should be
** from a file in the format of /etc/ethers) and returns in "eaddr" the
** ethernet address at the start of the line and the corresponding host
** name in "hostname". It assumes either tabs or spaces separate the
** two. The buffer pointed to by "hostname" must be big enough to hold
** the host name plus a NULL byte.
** The function returns 0 on success and 1 on failure.
** Arguments are assumed sensible. Null pointers will probably cause
** exceptions.
** Author: Gregory J. Sharp, July 1990
** Adapted to MINIX: Philip Homburg, May 1992
*/
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <net/gen/ether.h>
#include <net/gen/if_ether.h>
int
ether_line(line, eaddr, hostname)
char * line;
struct ether_addr * eaddr;
char * hostname;
{
register int i;
register unsigned long val;
/* skip leading white space */
while (*line != '\n' && (*line == ' ' || *line == '\t'))
line++;
/* read the ethernet address */
for (i = 0; i < 5; i++)
{
val = (unsigned long) strtol(line, &line, 16);
if (val > 255 || *line++ != ':')
return 1;
eaddr->ea_addr[i] = val & 0xff;
}
val = (unsigned long) strtol(line, &line, 16);
if (val > 255 || (*line != ' ' && *line != '\t'))
return 1;
eaddr->ea_addr[i] = val & 0xff;
/* skip leading white space */
while (*line != '\n' && (*line == ' ' || *line == '\t'))
line++;
/* read in the hostname */
while (!isspace(*line))
*hostname++ = *line++;
*hostname = '\0';
return 0;
}