1 /* vi: set sw=4 ts=4: */
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
15 #include <netinet/if_ether.h>
17 /* Please conditionalize exotic protocols on CONFIG_something */
19 static const uint16_t llproto_ids[] =
20 #define __PF(f,n) ETH_P_##f,
33 #ifdef ETH_P_IEEEPUPAT
34 __PF(IEEEPUPAT,ieeepupat)
50 __PF(PPP_DISC,ppp_disc)
70 __PF(LOCALTALK,localtalk)
72 __PF(TR_802_2,tr_802_2)
85 /* Keep declarations above and below in sync! */
87 static const char llproto_names[] =
88 #define __PF(f,n) #n "\0"
101 #ifdef ETH_P_IEEEPUPAT
102 __PF(IEEEPUPAT,ieeepupat)
117 #ifdef ETH_P_PPP_DISC
118 __PF(PPP_DISC,ppp_disc)
121 __PF(PPP_SES,ppp_ses)
124 __PF(ATMMPOA,atmmpoa)
127 __PF(ATMFATE,atmfate)
136 __PF(WAN_PPP,wan_ppp)
138 __PF(LOCALTALK,localtalk)
139 __PF(PPPTALK,ppptalk)
140 __PF(TR_802_2,tr_802_2)
141 __PF(MOBITEX,mobitex)
142 __PF(CONTROL,control)
154 const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
158 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
159 if (llproto_ids[i] == id)
160 return nth_string(llproto_names, i);
162 snprintf(buf, len, "[%u]", id);
166 int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
169 const char *name = llproto_names;
170 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
171 if (strcasecmp(name, buf) == 0) {
175 name += strlen(name) + 1;
178 i = bb_strtou(buf, NULL, 0);
179 if (errno || i > 0xffff)