Fri Jun 28 02:41:08 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / nss / nss_files / files-ethers.c
blobe7579a48bc69093d8c211d3bf4bdbf0d44afb096
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <string.h>
20 #include <netinet/if_ether.h>
22 /* Because the `ethers' lookup does not fit so well in the scheme so
23 we define a dummy struct here which helps us to use the available
24 functions. */
25 struct etherent
27 const char *e_name;
28 struct ether_addr e_addr;
30 struct etherent_data {};
32 #define ENTNAME etherent
33 #define DATAFILE "/etc/ethers"
34 #include "files-parse.c"
35 LINE_PARSER
37 MIDLINE_COMMENTS;
38 /* Read the ethernet address: 6 x 8bit hexadecimal number. */
40 size_t cnt;
42 for (cnt = 0; cnt < 6; ++cnt)
44 unsigned int number;
46 if (cnt < 5)
47 INT_FIELD (number, ISCOLON , 0, 16, (unsigned int))
48 else
49 INT_FIELD (number, isspace, 0, 16, (unsigned int))
51 if (number > 0xff)
52 return 0;
53 result->e_addr.ether_addr_octet[cnt] = number;
56 STRING_FIELD (result->e_name, isspace, 1);
60 #include "files-XXX.c"
62 DB_LOOKUP (hostton,
64 if (strcmp (result->e_name, name) == 0)
65 break;
66 }, const char *name)
68 DB_LOOKUP (ntohost,
70 if (memcmp (&result->e_addr, addr,
71 sizeof (struct ether_addr)) == 0)
72 break;
73 }, struct ether_addr *addr)