Initial public busybox upstream commit
[busybox4maemo] / networking / libiproute / ll_types.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * ll_types.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 #include <arpa/inet.h>
13 #include <linux/if_arp.h>
14
15 #include "libbb.h"
16 #include "rt_names.h"
17
18 const char *ll_type_n2a(int type, char *buf, int len)
19 {
20         static const char arphrd_name[] =
21         /* 0,                  */ "generic" "\0"
22         /* ARPHRD_LOOPBACK,    */ "loopback" "\0"
23         /* ARPHRD_ETHER,       */ "ether" "\0"
24 #ifdef ARPHRD_IEEE802_TR
25         /* ARPHRD_IEEE802,     */ "ieee802" "\0"
26         /* ARPHRD_IEEE802_TR,  */ "tr" "\0"
27 #else
28         /* ARPHRD_IEEE802,     */ "tr" "\0"
29 #endif
30 #ifdef ARPHRD_IEEE80211
31         /* ARPHRD_IEEE80211,   */ "ieee802.11" "\0"
32 #endif
33 #ifdef ARPHRD_IEEE1394
34         /* ARPHRD_IEEE1394,    */ "ieee1394" "\0"
35 #endif
36         /* ARPHRD_IRDA,        */ "irda" "\0"
37         /* ARPHRD_SLIP,        */ "slip" "\0"
38         /* ARPHRD_CSLIP,       */ "cslip" "\0"
39         /* ARPHRD_SLIP6,       */ "slip6" "\0"
40         /* ARPHRD_CSLIP6,      */ "cslip6" "\0"
41         /* ARPHRD_PPP,         */ "ppp" "\0"
42         /* ARPHRD_TUNNEL,      */ "ipip" "\0"
43         /* ARPHRD_TUNNEL6,     */ "tunnel6" "\0"
44         /* ARPHRD_SIT,         */ "sit" "\0"
45         /* ARPHRD_IPGRE,       */ "gre" "\0"
46 #ifdef ARPHRD_VOID
47         /* ARPHRD_VOID,        */ "void" "\0"
48 #endif
49
50 #if ENABLE_FEATURE_IP_RARE_PROTOCOLS
51         /* ARPHRD_EETHER,      */ "eether" "\0"
52         /* ARPHRD_AX25,        */ "ax25" "\0"
53         /* ARPHRD_PRONET,      */ "pronet" "\0"
54         /* ARPHRD_CHAOS,       */ "chaos" "\0"
55         /* ARPHRD_ARCNET,      */ "arcnet" "\0"
56         /* ARPHRD_APPLETLK,    */ "atalk" "\0"
57         /* ARPHRD_DLCI,        */ "dlci" "\0"
58 #ifdef ARPHRD_ATM
59         /* ARPHRD_ATM,         */ "atm" "\0"
60 #endif
61         /* ARPHRD_METRICOM,    */ "metricom" "\0"
62         /* ARPHRD_RSRVD,       */ "rsrvd" "\0"
63         /* ARPHRD_ADAPT,       */ "adapt" "\0"
64         /* ARPHRD_ROSE,        */ "rose" "\0"
65         /* ARPHRD_X25,         */ "x25" "\0"
66 #ifdef ARPHRD_HWX25
67         /* ARPHRD_HWX25,       */ "hwx25" "\0"
68 #endif
69         /* ARPHRD_HDLC,        */ "hdlc" "\0"
70         /* ARPHRD_LAPB,        */ "lapb" "\0"
71 #ifdef ARPHRD_DDCMP
72         /* ARPHRD_DDCMP,       */ "ddcmp" "\0"
73         /* ARPHRD_RAWHDLC,     */ "rawhdlc" "\0"
74 #endif
75         /* ARPHRD_FRAD,        */ "frad" "\0"
76         /* ARPHRD_SKIP,        */ "skip" "\0"
77         /* ARPHRD_LOCALTLK,    */ "ltalk" "\0"
78         /* ARPHRD_FDDI,        */ "fddi" "\0"
79         /* ARPHRD_BIF,         */ "bif" "\0"
80         /* ARPHRD_IPDDP,       */ "ip/ddp" "\0"
81         /* ARPHRD_PIMREG,      */ "pimreg" "\0"
82         /* ARPHRD_HIPPI,       */ "hippi" "\0"
83         /* ARPHRD_ASH,         */ "ash" "\0"
84         /* ARPHRD_ECONET,      */ "econet" "\0"
85         /* ARPHRD_FCPP,        */ "fcpp" "\0"
86         /* ARPHRD_FCAL,        */ "fcal" "\0"
87         /* ARPHRD_FCPL,        */ "fcpl" "\0"
88         /* ARPHRD_FCFABRIC,    */ "fcfb0" "\0"
89         /* ARPHRD_FCFABRIC+1,  */ "fcfb1" "\0"
90         /* ARPHRD_FCFABRIC+2,  */ "fcfb2" "\0"
91         /* ARPHRD_FCFABRIC+3,  */ "fcfb3" "\0"
92         /* ARPHRD_FCFABRIC+4,  */ "fcfb4" "\0"
93         /* ARPHRD_FCFABRIC+5,  */ "fcfb5" "\0"
94         /* ARPHRD_FCFABRIC+6,  */ "fcfb6" "\0"
95         /* ARPHRD_FCFABRIC+7,  */ "fcfb7" "\0"
96         /* ARPHRD_FCFABRIC+8,  */ "fcfb8" "\0"
97         /* ARPHRD_FCFABRIC+9,  */ "fcfb9" "\0"
98         /* ARPHRD_FCFABRIC+10, */ "fcfb10" "\0"
99         /* ARPHRD_FCFABRIC+11, */ "fcfb11" "\0"
100         /* ARPHRD_FCFABRIC+12, */ "fcfb12" "\0"
101 #endif /* FEATURE_IP_RARE_PROTOCOLS */
102         ;
103
104         /* Keep these arrays in sync! */
105
106         static const uint16_t arphrd_type[] = {
107         0,                  /* "generic" "\0" */
108         ARPHRD_LOOPBACK,    /* "loopback" "\0" */
109         ARPHRD_ETHER,       /* "ether" "\0" */
110 #ifdef ARPHRD_IEEE802_TR
111         ARPHRD_IEEE802,     /* "ieee802" "\0" */
112         ARPHRD_IEEE802_TR,  /* "tr" "\0" */
113 #else
114         ARPHRD_IEEE802,     /* "tr" "\0" */
115 #endif
116 #ifdef ARPHRD_IEEE80211
117         ARPHRD_IEEE80211,   /* "ieee802.11" "\0" */
118 #endif
119 #ifdef ARPHRD_IEEE1394
120         ARPHRD_IEEE1394,    /* "ieee1394" "\0" */
121 #endif
122         ARPHRD_IRDA,        /* "irda" "\0" */
123         ARPHRD_SLIP,        /* "slip" "\0" */
124         ARPHRD_CSLIP,       /* "cslip" "\0" */
125         ARPHRD_SLIP6,       /* "slip6" "\0" */
126         ARPHRD_CSLIP6,      /* "cslip6" "\0" */
127         ARPHRD_PPP,         /* "ppp" "\0" */
128         ARPHRD_TUNNEL,      /* "ipip" "\0" */
129         ARPHRD_TUNNEL6,     /* "tunnel6" "\0" */
130         ARPHRD_SIT,         /* "sit" "\0" */
131         ARPHRD_IPGRE,       /* "gre" "\0" */
132 #ifdef ARPHRD_VOID
133         ARPHRD_VOID,        /* "void" "\0" */
134 #endif
135
136 #if ENABLE_FEATURE_IP_RARE_PROTOCOLS
137         ARPHRD_EETHER,      /* "eether" "\0" */
138         ARPHRD_AX25,        /* "ax25" "\0" */
139         ARPHRD_PRONET,      /* "pronet" "\0" */
140         ARPHRD_CHAOS,       /* "chaos" "\0" */
141         ARPHRD_ARCNET,      /* "arcnet" "\0" */
142         ARPHRD_APPLETLK,    /* "atalk" "\0" */
143         ARPHRD_DLCI,        /* "dlci" "\0" */
144 #ifdef ARPHRD_ATM
145         ARPHRD_ATM,         /* "atm" "\0" */
146 #endif
147         ARPHRD_METRICOM,    /* "metricom" "\0" */
148         ARPHRD_RSRVD,       /* "rsrvd" "\0" */
149         ARPHRD_ADAPT,       /* "adapt" "\0" */
150         ARPHRD_ROSE,        /* "rose" "\0" */
151         ARPHRD_X25,         /* "x25" "\0" */
152 #ifdef ARPHRD_HWX25
153         ARPHRD_HWX25,       /* "hwx25" "\0" */
154 #endif
155         ARPHRD_HDLC,        /* "hdlc" "\0" */
156         ARPHRD_LAPB,        /* "lapb" "\0" */
157 #ifdef ARPHRD_DDCMP
158         ARPHRD_DDCMP,       /* "ddcmp" "\0" */
159         ARPHRD_RAWHDLC,     /* "rawhdlc" "\0" */
160 #endif
161         ARPHRD_FRAD,        /* "frad" "\0" */
162         ARPHRD_SKIP,        /* "skip" "\0" */
163         ARPHRD_LOCALTLK,    /* "ltalk" "\0" */
164         ARPHRD_FDDI,        /* "fddi" "\0" */
165         ARPHRD_BIF,         /* "bif" "\0" */
166         ARPHRD_IPDDP,       /* "ip/ddp" "\0" */
167         ARPHRD_PIMREG,      /* "pimreg" "\0" */
168         ARPHRD_HIPPI,       /* "hippi" "\0" */
169         ARPHRD_ASH,         /* "ash" "\0" */
170         ARPHRD_ECONET,      /* "econet" "\0" */
171         ARPHRD_FCPP,        /* "fcpp" "\0" */
172         ARPHRD_FCAL,        /* "fcal" "\0" */
173         ARPHRD_FCPL,        /* "fcpl" "\0" */
174         ARPHRD_FCFABRIC,    /* "fcfb0" "\0" */
175         ARPHRD_FCFABRIC+1,  /* "fcfb1" "\0" */
176         ARPHRD_FCFABRIC+2,  /* "fcfb2" "\0" */
177         ARPHRD_FCFABRIC+3,  /* "fcfb3" "\0" */
178         ARPHRD_FCFABRIC+4,  /* "fcfb4" "\0" */
179         ARPHRD_FCFABRIC+5,  /* "fcfb5" "\0" */
180         ARPHRD_FCFABRIC+6,  /* "fcfb6" "\0" */
181         ARPHRD_FCFABRIC+7,  /* "fcfb7" "\0" */
182         ARPHRD_FCFABRIC+8,  /* "fcfb8" "\0" */
183         ARPHRD_FCFABRIC+9,  /* "fcfb9" "\0" */
184         ARPHRD_FCFABRIC+10, /* "fcfb10" "\0" */
185         ARPHRD_FCFABRIC+11, /* "fcfb11" "\0" */
186         ARPHRD_FCFABRIC+12, /* "fcfb12" "\0" */
187 #endif /* FEATURE_IP_RARE_PROTOCOLS */
188         };
189
190         int i;
191         const char *aname = arphrd_name;
192         for (i = 0; i < ARRAY_SIZE(arphrd_type); i++) {
193                 if (arphrd_type[i] == type)
194                         return aname;
195                 aname += strlen(aname) + 1;
196         }
197         snprintf(buf, len, "[%d]", type);
198         return buf;
199 }