]> git.ipfire.org Git - thirdparty/glibc.git/blob - nss/nss_files/files-ethers.c
290d931c9712a7a17c11a410bf3f8b58448f795e
[thirdparty/glibc.git] / nss / nss_files / files-ethers.c
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 #include <string.h>
20 #include <netinet/if_ether.h>
21
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
26 {
27 const char *e_name;
28 struct ether_addr e_addr;
29 };
30 struct etherent_data {};
31
32 #define ENTNAME etherent
33 #define DATABASE "ethers"
34 #include "files-parse.c"
35 LINE_PARSER
36 ("#",
37 /* Read the ethernet address: 6 x 8bit hexadecimal number. */
38 {
39 size_t cnt;
40
41 for (cnt = 0; cnt < 6; ++cnt)
42 {
43 unsigned int number;
44
45 if (cnt < 5)
46 INT_FIELD (number, ISCOLON , 0, 16, (unsigned int))
47 else
48 INT_FIELD (number, isspace, 0, 16, (unsigned int))
49
50 if (number > 0xff)
51 return 0;
52 result->e_addr.ether_addr_octet[cnt] = number;
53 }
54 };
55 STRING_FIELD (result->e_name, isspace, 1);
56 )
57
58
59 #include GENERIC
60
61 DB_LOOKUP (hostton, 1 + strlen (name), (".%s", name),
62 {
63 if (strcmp (result->e_name, name) == 0)
64 break;
65 }, const char *name)
66
67 DB_LOOKUP (ntohost, 18, ("=%x:%x:%x:%x:%x:%x",
68 addr->ether_addr_octet[0], addr->ether_addr_octet[1],
69 addr->ether_addr_octet[2], addr->ether_addr_octet[3],
70 addr->ether_addr_octet[4], addr->ether_addr_octet[5]),
71 {
72 if (memcmp (&result->e_addr, addr,
73 sizeof (struct ether_addr)) == 0)
74 break;
75 }, struct ether_addr *addr)