Contents of /trunk/mkinitrd-magellan/busybox/networking/libiproute/ll_proto.c
Parent Directory | Revision Log
Revision 984 -
(show annotations)
(download)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 2565 byte(s)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 2565 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * ll_proto.c |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License |
7 | * as published by the Free Software Foundation; either version |
8 | * 2 of the License, or (at your option) any later version. |
9 | * |
10 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
11 | */ |
12 | |
13 | #include "libbb.h" |
14 | #include "rt_names.h" |
15 | #include "utils.h" |
16 | |
17 | #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 |
18 | #include <net/ethernet.h> |
19 | #else |
20 | #include <linux/if_ether.h> |
21 | #endif |
22 | |
23 | #if !ENABLE_WERROR |
24 | #warning de-bloat |
25 | #endif |
26 | /* Before re-enabling this, please (1) conditionalize exotic protocols |
27 | * on CONFIG_something, and (2) decouple strings and numbers |
28 | * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) |
29 | */ |
30 | |
31 | #define __PF(f,n) { ETH_P_##f, #n }, |
32 | static struct { |
33 | int id; |
34 | const char *name; |
35 | } llproto_names[] = { |
36 | __PF(LOOP,loop) |
37 | __PF(PUP,pup) |
38 | #ifdef ETH_P_PUPAT |
39 | __PF(PUPAT,pupat) |
40 | #endif |
41 | __PF(IP,ip) |
42 | __PF(X25,x25) |
43 | __PF(ARP,arp) |
44 | __PF(BPQ,bpq) |
45 | #ifdef ETH_P_IEEEPUP |
46 | __PF(IEEEPUP,ieeepup) |
47 | #endif |
48 | #ifdef ETH_P_IEEEPUPAT |
49 | __PF(IEEEPUPAT,ieeepupat) |
50 | #endif |
51 | __PF(DEC,dec) |
52 | __PF(DNA_DL,dna_dl) |
53 | __PF(DNA_RC,dna_rc) |
54 | __PF(DNA_RT,dna_rt) |
55 | __PF(LAT,lat) |
56 | __PF(DIAG,diag) |
57 | __PF(CUST,cust) |
58 | __PF(SCA,sca) |
59 | __PF(RARP,rarp) |
60 | __PF(ATALK,atalk) |
61 | __PF(AARP,aarp) |
62 | __PF(IPX,ipx) |
63 | __PF(IPV6,ipv6) |
64 | #ifdef ETH_P_PPP_DISC |
65 | __PF(PPP_DISC,ppp_disc) |
66 | #endif |
67 | #ifdef ETH_P_PPP_SES |
68 | __PF(PPP_SES,ppp_ses) |
69 | #endif |
70 | #ifdef ETH_P_ATMMPOA |
71 | __PF(ATMMPOA,atmmpoa) |
72 | #endif |
73 | #ifdef ETH_P_ATMFATE |
74 | __PF(ATMFATE,atmfate) |
75 | #endif |
76 | |
77 | __PF(802_3,802_3) |
78 | __PF(AX25,ax25) |
79 | __PF(ALL,all) |
80 | __PF(802_2,802_2) |
81 | __PF(SNAP,snap) |
82 | __PF(DDCMP,ddcmp) |
83 | __PF(WAN_PPP,wan_ppp) |
84 | __PF(PPP_MP,ppp_mp) |
85 | __PF(LOCALTALK,localtalk) |
86 | __PF(PPPTALK,ppptalk) |
87 | __PF(TR_802_2,tr_802_2) |
88 | __PF(MOBITEX,mobitex) |
89 | __PF(CONTROL,control) |
90 | __PF(IRDA,irda) |
91 | #ifdef ETH_P_ECONET |
92 | __PF(ECONET,econet) |
93 | #endif |
94 | |
95 | { 0x8100, "802.1Q" }, |
96 | { ETH_P_IP, "ipv4" }, |
97 | }; |
98 | #undef __PF |
99 | |
100 | |
101 | const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len) |
102 | { |
103 | unsigned i; |
104 | id = ntohs(id); |
105 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
106 | if (llproto_names[i].id == id) |
107 | return llproto_names[i].name; |
108 | } |
109 | snprintf(buf, len, "[%d]", id); |
110 | return buf; |
111 | } |
112 | |
113 | int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) |
114 | { |
115 | unsigned i; |
116 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
117 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
118 | i = llproto_names[i].id; |
119 | goto good; |
120 | } |
121 | } |
122 | i = bb_strtou(buf, NULL, 0); |
123 | if (errno || i > 0xffff) |
124 | return -1; |
125 | good: |
126 | *id = htons(i); |
127 | return 0; |
128 | } |
129 |