source: MondoRescue/branches/3.3/mindi-busybox/networking/libiproute/ll_proto.c@ 3909

Last change on this file since 3909 was 3621, checked in by Bruno Cornec, 10 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 3.3 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
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.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 */
10
11#include "libbb.h"
12#include "rt_names.h"
13#include "utils.h"
14
15#include <netinet/if_ether.h>
16
17/* Please conditionalize exotic protocols on CONFIG_something */
18
19static const uint16_t llproto_ids[] = {
20#define __PF(f,n) ETH_P_##f,
21__PF(LOOP,loop)
22__PF(PUP,pup)
23#ifdef ETH_P_PUPAT
24__PF(PUPAT,pupat)
25#endif
26__PF(IP,ip)
27__PF(X25,x25)
28__PF(ARP,arp)
29__PF(BPQ,bpq)
30#ifdef ETH_P_IEEEPUP
31__PF(IEEEPUP,ieeepup)
32#endif
33#ifdef ETH_P_IEEEPUPAT
34__PF(IEEEPUPAT,ieeepupat)
35#endif
36__PF(DEC,dec)
37__PF(DNA_DL,dna_dl)
38__PF(DNA_RC,dna_rc)
39__PF(DNA_RT,dna_rt)
40__PF(LAT,lat)
41__PF(DIAG,diag)
42__PF(CUST,cust)
43__PF(SCA,sca)
44__PF(RARP,rarp)
45__PF(ATALK,atalk)
46__PF(AARP,aarp)
47__PF(IPX,ipx)
48__PF(IPV6,ipv6)
49#ifdef ETH_P_PPP_DISC
50__PF(PPP_DISC,ppp_disc)
51#endif
52#ifdef ETH_P_PPP_SES
53__PF(PPP_SES,ppp_ses)
54#endif
55#ifdef ETH_P_ATMMPOA
56__PF(ATMMPOA,atmmpoa)
57#endif
58#ifdef ETH_P_ATMFATE
59__PF(ATMFATE,atmfate)
60#endif
61
62__PF(802_3,802_3)
63__PF(AX25,ax25)
64__PF(ALL,all)
65__PF(802_2,802_2)
66__PF(SNAP,snap)
67__PF(DDCMP,ddcmp)
68__PF(WAN_PPP,wan_ppp)
69__PF(PPP_MP,ppp_mp)
70__PF(LOCALTALK,localtalk)
71__PF(PPPTALK,ppptalk)
72__PF(TR_802_2,tr_802_2)
73__PF(MOBITEX,mobitex)
74__PF(CONTROL,control)
75__PF(IRDA,irda)
76#ifdef ETH_P_ECONET
77__PF(ECONET,econet)
78#endif
79
800x8100,
81ETH_P_IP
82};
83#undef __PF
84
85/* Keep declarations above and below in sync! */
86
87static const char llproto_names[] ALIGN1 =
88#define __PF(f,n) #n "\0"
89__PF(LOOP,loop)
90__PF(PUP,pup)
91#ifdef ETH_P_PUPAT
92__PF(PUPAT,pupat)
93#endif
94__PF(IP,ip)
95__PF(X25,x25)
96__PF(ARP,arp)
97__PF(BPQ,bpq)
98#ifdef ETH_P_IEEEPUP
99__PF(IEEEPUP,ieeepup)
100#endif
101#ifdef ETH_P_IEEEPUPAT
102__PF(IEEEPUPAT,ieeepupat)
103#endif
104__PF(DEC,dec)
105__PF(DNA_DL,dna_dl)
106__PF(DNA_RC,dna_rc)
107__PF(DNA_RT,dna_rt)
108__PF(LAT,lat)
109__PF(DIAG,diag)
110__PF(CUST,cust)
111__PF(SCA,sca)
112__PF(RARP,rarp)
113__PF(ATALK,atalk)
114__PF(AARP,aarp)
115__PF(IPX,ipx)
116__PF(IPV6,ipv6)
117#ifdef ETH_P_PPP_DISC
118__PF(PPP_DISC,ppp_disc)
119#endif
120#ifdef ETH_P_PPP_SES
121__PF(PPP_SES,ppp_ses)
122#endif
123#ifdef ETH_P_ATMMPOA
124__PF(ATMMPOA,atmmpoa)
125#endif
126#ifdef ETH_P_ATMFATE
127__PF(ATMFATE,atmfate)
128#endif
129
130__PF(802_3,802_3)
131__PF(AX25,ax25)
132__PF(ALL,all)
133__PF(802_2,802_2)
134__PF(SNAP,snap)
135__PF(DDCMP,ddcmp)
136__PF(WAN_PPP,wan_ppp)
137__PF(PPP_MP,ppp_mp)
138__PF(LOCALTALK,localtalk)
139__PF(PPPTALK,ppptalk)
140__PF(TR_802_2,tr_802_2)
141__PF(MOBITEX,mobitex)
142__PF(CONTROL,control)
143__PF(IRDA,irda)
144#ifdef ETH_P_ECONET
145__PF(ECONET,econet)
146#endif
147
148"802.1Q" "\0"
149"ipv4" "\0"
150;
151#undef __PF
152
153
154const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
155{
156 unsigned i;
157 id = ntohs(id);
158 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
159 if (llproto_ids[i] == id)
160 return nth_string(llproto_names, i);
161 }
162 snprintf(buf, len, "[%u]", id);
163 return buf;
164}
165
166int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
167{
168 unsigned i;
169 const char *name = llproto_names;
170 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
171 if (strcasecmp(name, buf) == 0) {
172 i = llproto_ids[i];
173 goto good;
174 }
175 name += strlen(name) + 1;
176 }
177 errno = 0;
178 i = bb_strtou(buf, NULL, 0);
179 if (errno || i > 0xffff)
180 return -1;
181 good:
182 *id = htons(i);
183 return 0;
184}
Note: See TracBrowser for help on using the repository browser.