4 * This file was part of the NYS Library.
6 ** The NYS Library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Library General Public License as
8 ** published by the Free Software Foundation; either version 2 of the
9 ** License, or (at your option) any later version.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /********************************************************************
27 * Description: Ethertype name service switch and the ethertypes
28 * database access functions
29 * Author: Nick Fedchik <fnm@ukrsat.com>
30 * Checker: Bart De Schuymer <bdschuym@pandora.be>
31 * Origin: uClibc-0.9.16/libc/inet/getproto.c
32 * Created at: Mon Nov 11 12:20:11 EET 2002
33 ********************************************************************/
37 #include <sys/types.h>
38 #include <sys/socket.h>
43 #include <netinet/ether.h>
44 #include <net/ethernet.h>
46 #include "ethernetdb.h"
50 static FILE *etherf
= NULL
;
51 static char line
[BUFSIZ
+ 1];
52 static struct ethertypeent et_ent
;
53 static char *ethertype_aliases
[MAXALIASES
];
54 static int ethertype_stayopen
;
56 void setethertypeent(int f
)
59 etherf
= fopen(_PATH_ETHERTYPES
, "r");
62 ethertype_stayopen
|= f
;
65 void endethertypeent(void)
71 ethertype_stayopen
= 0;
74 struct ethertypeent
*getethertypeent(void)
78 register char *cp
, **q
;
81 && (etherf
= fopen(_PATH_ETHERTYPES
, "r")) == NULL
) {
86 if ((e
= fgets(line
, BUFSIZ
, etherf
)) == NULL
) {
91 cp
= strpbrk(e
, "#\n");
96 cp
= strpbrk(e
, " \t");
100 while (*cp
== ' ' || *cp
== '\t')
102 e
= strpbrk(cp
, " \t");
106 et_ent
.e_ethertype
= strtol(cp
, &endptr
, 16);
108 || (et_ent
.e_ethertype
< ETH_ZLEN
109 || et_ent
.e_ethertype
> 0xFFFF))
110 goto again
; // Skip invalid etherproto type entry
111 q
= et_ent
.e_aliases
= ethertype_aliases
;
115 if (*cp
== ' ' || *cp
== '\t') {
119 if (q
< ðertype_aliases
[MAXALIASES
- 1])
121 cp
= strpbrk(cp
, " \t");
131 struct ethertypeent
*getethertypebyname(const char *name
)
133 register struct ethertypeent
*e
;
136 setethertypeent(ethertype_stayopen
);
137 while ((e
= getethertypeent()) != NULL
) {
138 if (strcasecmp(e
->e_name
, name
) == 0)
140 for (cp
= e
->e_aliases
; *cp
!= 0; cp
++)
141 if (strcasecmp(*cp
, name
) == 0)
145 if (!ethertype_stayopen
)
150 struct ethertypeent
*getethertypebynumber(int type
)
152 register struct ethertypeent
*e
;
154 setethertypeent(ethertype_stayopen
);
155 while ((e
= getethertypeent()) != NULL
)
156 if (e
->e_ethertype
== type
)
158 if (!ethertype_stayopen
)