Contents of /trunk/mkinitrd-magellan/busybox/networking/libiproute/ll_proto.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2280 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2280 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
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 | |
15 | #include "rt_names.h" |
16 | #include "utils.h" |
17 | |
18 | #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 |
19 | #include <net/ethernet.h> |
20 | #else |
21 | #include <linux/if_ether.h> |
22 | #endif |
23 | |
24 | #define __PF(f,n) { ETH_P_##f, #n }, |
25 | static struct { |
26 | int id; |
27 | char *name; |
28 | } llproto_names[] = { |
29 | __PF(LOOP,loop) |
30 | __PF(PUP,pup) |
31 | #ifdef ETH_P_PUPAT |
32 | __PF(PUPAT,pupat) |
33 | #endif |
34 | __PF(IP,ip) |
35 | __PF(X25,x25) |
36 | __PF(ARP,arp) |
37 | __PF(BPQ,bpq) |
38 | #ifdef ETH_P_IEEEPUP |
39 | __PF(IEEEPUP,ieeepup) |
40 | #endif |
41 | #ifdef ETH_P_IEEEPUPAT |
42 | __PF(IEEEPUPAT,ieeepupat) |
43 | #endif |
44 | __PF(DEC,dec) |
45 | __PF(DNA_DL,dna_dl) |
46 | __PF(DNA_RC,dna_rc) |
47 | __PF(DNA_RT,dna_rt) |
48 | __PF(LAT,lat) |
49 | __PF(DIAG,diag) |
50 | __PF(CUST,cust) |
51 | __PF(SCA,sca) |
52 | __PF(RARP,rarp) |
53 | __PF(ATALK,atalk) |
54 | __PF(AARP,aarp) |
55 | __PF(IPX,ipx) |
56 | __PF(IPV6,ipv6) |
57 | #ifdef ETH_P_PPP_DISC |
58 | __PF(PPP_DISC,ppp_disc) |
59 | #endif |
60 | #ifdef ETH_P_PPP_SES |
61 | __PF(PPP_SES,ppp_ses) |
62 | #endif |
63 | #ifdef ETH_P_ATMMPOA |
64 | __PF(ATMMPOA,atmmpoa) |
65 | #endif |
66 | #ifdef ETH_P_ATMFATE |
67 | __PF(ATMFATE,atmfate) |
68 | #endif |
69 | |
70 | __PF(802_3,802_3) |
71 | __PF(AX25,ax25) |
72 | __PF(ALL,all) |
73 | __PF(802_2,802_2) |
74 | __PF(SNAP,snap) |
75 | __PF(DDCMP,ddcmp) |
76 | __PF(WAN_PPP,wan_ppp) |
77 | __PF(PPP_MP,ppp_mp) |
78 | __PF(LOCALTALK,localtalk) |
79 | __PF(PPPTALK,ppptalk) |
80 | __PF(TR_802_2,tr_802_2) |
81 | __PF(MOBITEX,mobitex) |
82 | __PF(CONTROL,control) |
83 | __PF(IRDA,irda) |
84 | #ifdef ETH_P_ECONET |
85 | __PF(ECONET,econet) |
86 | #endif |
87 | |
88 | { 0x8100, "802.1Q" }, |
89 | { ETH_P_IP, "ipv4" }, |
90 | }; |
91 | #undef __PF |
92 | |
93 | |
94 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) |
95 | { |
96 | int i; |
97 | |
98 | id = ntohs(id); |
99 | |
100 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
101 | if (llproto_names[i].id == id) |
102 | return llproto_names[i].name; |
103 | } |
104 | snprintf(buf, len, "[%d]", id); |
105 | return buf; |
106 | } |
107 | |
108 | int ll_proto_a2n(unsigned short *id, char *buf) |
109 | { |
110 | int i; |
111 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
112 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
113 | *id = htons(llproto_names[i].id); |
114 | return 0; |
115 | } |
116 | } |
117 | if (get_u16(id, buf, 0)) |
118 | return -1; |
119 | *id = htons(*id); |
120 | return 0; |
121 | } |