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 <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <string.h>
22
23 #include <linux/netdevice.h>
24 #include <linux/if_arp.h>
25 #include <linux/sockios.h>
26
27 #include "rt_names.h"
28
ll_type_n2a(int type,char * buf,int len)29 const char * ll_type_n2a(int type, char *buf, int len)
30 {
31 #define __PF(f,n) { ARPHRD_##f, #n },
32 static const struct {
33 int type;
34 const char *name;
35 } arphrd_names[] = {
36 { 0, "generic" },
37 __PF(ETHER,ether)
38 __PF(EETHER,eether)
39 __PF(AX25,ax25)
40 __PF(PRONET,pronet)
41 __PF(CHAOS,chaos)
42 __PF(IEEE802,ieee802)
43 __PF(ARCNET,arcnet)
44 __PF(APPLETLK,atalk)
45 __PF(DLCI,dlci)
46 __PF(ATM,atm)
47 __PF(METRICOM,metricom)
48 __PF(IEEE1394,ieee1394)
49 __PF(INFINIBAND,infiniband)
50 __PF(SLIP,slip)
51 __PF(CSLIP,cslip)
52 __PF(SLIP6,slip6)
53 __PF(CSLIP6,cslip6)
54 __PF(RSRVD,rsrvd)
55 __PF(ADAPT,adapt)
56 __PF(ROSE,rose)
57 __PF(X25,x25)
58 __PF(HWX25,hwx25)
59 __PF(CAN,can)
60 __PF(PPP,ppp)
61 __PF(HDLC,hdlc)
62 __PF(LAPB,lapb)
63 __PF(DDCMP,ddcmp)
64 __PF(RAWHDLC,rawhdlc)
65 __PF(TUNNEL,ipip)
66 __PF(TUNNEL6,tunnel6)
67 __PF(FRAD,frad)
68 __PF(SKIP,skip)
69 __PF(LOOPBACK,loopback)
70 __PF(LOCALTLK,ltalk)
71 __PF(FDDI,fddi)
72 __PF(BIF,bif)
73 __PF(SIT,sit)
74 __PF(IPDDP,ip/ddp)
75 __PF(IPGRE,gre)
76 __PF(PIMREG,pimreg)
77 __PF(HIPPI,hippi)
78 __PF(ASH,ash)
79 __PF(ECONET,econet)
80 __PF(IRDA,irda)
81 __PF(FCPP,fcpp)
82 __PF(FCAL,fcal)
83 __PF(FCPL,fcpl)
84 __PF(FCFABRIC,fcfb0)
85 __PF(FCFABRIC+1,fcfb1)
86 __PF(FCFABRIC+2,fcfb2)
87 __PF(FCFABRIC+3,fcfb3)
88 __PF(FCFABRIC+4,fcfb4)
89 __PF(FCFABRIC+5,fcfb5)
90 __PF(FCFABRIC+6,fcfb6)
91 __PF(FCFABRIC+7,fcfb7)
92 __PF(FCFABRIC+8,fcfb8)
93 __PF(FCFABRIC+9,fcfb9)
94 __PF(FCFABRIC+10,fcfb10)
95 __PF(FCFABRIC+11,fcfb11)
96 __PF(FCFABRIC+12,fcfb12)
97 __PF(IEEE802_TR,tr)
98 __PF(IEEE80211,ieee802.11)
99 __PF(IEEE80211_PRISM,ieee802.11/prism)
100 __PF(IEEE80211_RADIOTAP,ieee802.11/radiotap)
101 __PF(IEEE802154, ieee802.15.4)
102 __PF(IEEE802154_MONITOR, ieee802.15.4/monitor)
103 __PF(PHONET, phonet)
104 __PF(PHONET_PIPE, phonet_pipe)
105 __PF(CAIF, caif)
106 __PF(IP6GRE, gre6)
107 __PF(NETLINK, netlink)
108 __PF(6LOWPAN, 6lowpan)
109
110 __PF(NONE, none)
111 __PF(VOID,void)
112 };
113 #undef __PF
114
115 int i;
116 for (i=0; i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
117 if (arphrd_names[i].type == type)
118 return arphrd_names[i].name;
119 }
120 snprintf(buf, len, "[%d]", type);
121 return buf;
122 }
123