38 #include <sys/types.h>
39 #include <sys/socket.h>
44 #include <netinet/ether.h>
45 #include <net/ethernet.h>
47 #include "ethernetdb.h"
51 static FILE *etherf = NULL;
52 static char line[BUFSIZ + 1];
54 static char *ethertype_aliases[MAXALIASES];
55 static int ethertype_stayopen;
57 void setethertypeent(
int f)
60 etherf = fopen(_PATH_ETHERTYPES,
"r");
63 ethertype_stayopen |= f;
66 void endethertypeent(
void)
72 ethertype_stayopen = 0;
79 register char *cp, **q;
82 && (etherf = fopen(_PATH_ETHERTYPES,
"r")) == NULL) {
87 if ((e = fgets(line, BUFSIZ, etherf)) == NULL) {
92 cp = strpbrk(e,
"#\n");
97 cp = strpbrk(e,
" \t");
101 while (*cp ==
' ' || *cp ==
'\t')
103 e = strpbrk(cp,
" \t");
107 et_ent.e_ethertype = strtol(cp, &endptr, 16);
109 || (et_ent.e_ethertype < ETH_ZLEN
110 || et_ent.e_ethertype > 0xFFFF))
112 q = et_ent.e_aliases = ethertype_aliases;
116 if (*cp ==
' ' || *cp ==
'\t') {
120 if (q < ðertype_aliases[MAXALIASES - 1])
122 cp = strpbrk(cp,
" \t");
132 struct ethertypeent *getethertypebyname(
const char *name)
137 setethertypeent(ethertype_stayopen);
138 while ((e = getethertypeent()) != NULL) {
139 if (strcasecmp(e->e_name, name) == 0)
141 for (cp = e->e_aliases; *cp != 0; cp++)
142 if (strcasecmp(*cp, name) == 0)
146 if (!ethertype_stayopen)
155 setethertypeent(ethertype_stayopen);
156 while ((e = getethertypeent()) != NULL)
157 if (e->e_ethertype == type)
159 if (!ethertype_stayopen)