Patch from Bastian Blank:
[oweals/busybox.git] / networking / libiproute / ll_types.c
1 /*
2  * ll_types.c
3  *
4  *              This program is free software; you can redistribute it and/or
5  *              modify it under the terms of the GNU General Public License
6  *              as published by the Free Software Foundation; either version
7  *              2 of the License, or (at your option) any later version.
8  *
9  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10  */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <syslog.h>
16 #include <fcntl.h>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
19 #include <sys/ioctl.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <string.h>
23
24 #include <linux/netdevice.h>
25 #include <linux/if_arp.h>
26 #include <linux/sockios.h>
27
28 char * ll_type_n2a(int type, char *buf, int len)
29 {
30 #define __PF(f,n) { ARPHRD_##f, #n },
31 static struct {
32         int type;
33         char *name;
34 } arphrd_names[] = {
35 { 0, "generic" },
36 __PF(ETHER,ether)
37 __PF(EETHER,eether)
38 __PF(AX25,ax25)
39 __PF(PRONET,pronet)
40 __PF(CHAOS,chaos)
41 #ifdef ARPHRD_IEEE802_TR
42 __PF(IEEE802,ieee802)
43 #else
44 __PF(IEEE802,tr)
45 #endif
46 __PF(ARCNET,arcnet)
47 __PF(APPLETLK,atalk)
48 __PF(DLCI,dlci)
49 __PF(ATM,atm)
50 __PF(METRICOM,metricom)
51 #ifdef ARPHRD_IEEE1394
52 __PF(IEEE1394,ieee1394)
53 #endif
54
55 __PF(SLIP,slip)
56 __PF(CSLIP,cslip)
57 __PF(SLIP6,slip6)
58 __PF(CSLIP6,cslip6)
59 __PF(RSRVD,rsrvd)
60 __PF(ADAPT,adapt)
61 __PF(ROSE,rose)
62 __PF(X25,x25)
63 __PF(HWX25,hwx25)
64 __PF(PPP,ppp)
65 __PF(HDLC,hdlc)
66 __PF(LAPB,lapb)
67 __PF(DDCMP,ddcmp)
68 __PF(RAWHDLC,rawhdlc)
69
70 __PF(TUNNEL,ipip)
71 __PF(TUNNEL6,tunnel6)
72 __PF(FRAD,frad)
73 __PF(SKIP,skip)
74 __PF(LOOPBACK,loopback)
75 __PF(LOCALTLK,ltalk)
76 __PF(FDDI,fddi)
77 __PF(BIF,bif)
78 __PF(SIT,sit)
79 __PF(IPDDP,ip/ddp)
80 __PF(IPGRE,gre)
81 __PF(PIMREG,pimreg)
82 __PF(HIPPI,hippi)
83 __PF(ASH,ash)
84 __PF(ECONET,econet)
85 __PF(IRDA,irda)
86 __PF(FCPP,fcpp)
87 __PF(FCAL,fcal)
88 __PF(FCPL,fcpl)
89 __PF(FCFABRIC,fcfb0)
90 __PF(FCFABRIC+1,fcfb1)
91 __PF(FCFABRIC+2,fcfb2)
92 __PF(FCFABRIC+3,fcfb3)
93 __PF(FCFABRIC+4,fcfb4)
94 __PF(FCFABRIC+5,fcfb5)
95 __PF(FCFABRIC+6,fcfb6)
96 __PF(FCFABRIC+7,fcfb7)
97 __PF(FCFABRIC+8,fcfb8)
98 __PF(FCFABRIC+9,fcfb9)
99 __PF(FCFABRIC+10,fcfb10)
100 __PF(FCFABRIC+11,fcfb11)
101 __PF(FCFABRIC+12,fcfb12)
102 #ifdef ARPHRD_IEEE802_TR
103 __PF(IEEE802_TR,tr)
104 #endif
105 #ifdef ARPHRD_IEEE80211
106 __PF(IEEE80211,ieee802.11)
107 #endif
108 #ifdef ARPHRD_VOID
109 __PF(VOID,void)
110 #endif
111 };
112 #undef __PF
113
114         int i;
115         for (i=0; i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
116                  if (arphrd_names[i].type == type)
117                         return arphrd_names[i].name;
118         }
119         snprintf(buf, len, "[%d]", type);
120         return buf;
121 }