source: trunk/minix/lib/ip/ether_line.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.6 KB
Line 
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
15*/
16
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>
22
23int
24ether_line(line, eaddr, hostname)
25char * line;
26struct ether_addr * eaddr;
27char * hostname;
28{
29 register int i;
30 register unsigned long val;
31
32/* skip leading white space */
33 while (*line != '\n' && (*line == ' ' || *line == '\t'))
34 line++;
35
36/* read the ethernet address */
37 for (i = 0; i < 5; i++)
38 {
39 val = (unsigned long) strtol(line, &line, 16);
40 if (val > 255 || *line++ != ':')
41 return 1;
42 eaddr->ea_addr[i] = val & 0xff;
43 }
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;
48
49/* skip leading white space */
50 while (*line != '\n' && (*line == ' ' || *line == '\t'))
51 line++;
52
53/* read in the hostname */
54 while (!isspace(*line))
55 *hostname++ = *line++;
56 *hostname = '\0';
57 return 0;
58}
Note: See TracBrowser for help on using the repository browser.