1
2
3
4
5
6
7
8
9
10
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <fcntl.h>
16#include <sys/ioctl.h>
17#include <sys/socket.h>
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <string.h>
21
22#include <linux/netdevice.h>
23#include <linux/if_arp.h>
24#include <linux/sockios.h>
25
26#include "utils.h"
27#include "rt_names.h"
28
29
30#define __PF(f,n) { ETH_P_##f, #n },
31static const struct {
32 int id;
33 const char *name;
34} llproto_names[] = {
35__PF(LOOP,loop)
36__PF(PUP,pup)
37__PF(PUPAT,pupat)
38__PF(IP,ip)
39__PF(X25,x25)
40__PF(ARP,arp)
41__PF(BPQ,bpq)
42__PF(IEEEPUP,ieeepup)
43__PF(IEEEPUPAT,ieeepupat)
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__PF(PPP_DISC,ppp_disc)
58__PF(PPP_SES,ppp_ses)
59__PF(ATMMPOA,atmmpoa)
60__PF(ATMFATE,atmfate)
61__PF(802_3,802_3)
62__PF(AX25,ax25)
63__PF(ALL,all)
64__PF(802_2,802_2)
65__PF(SNAP,snap)
66__PF(DDCMP,ddcmp)
67__PF(WAN_PPP,wan_ppp)
68__PF(PPP_MP,ppp_mp)
69__PF(LOCALTALK,localtalk)
70__PF(CAN,can)
71__PF(PPPTALK,ppptalk)
72__PF(TR_802_2,tr_802_2)
73__PF(MOBITEX,mobitex)
74__PF(CONTROL,control)
75__PF(IRDA,irda)
76__PF(ECONET,econet)
77__PF(TIPC,tipc)
78__PF(AOE,aoe)
79__PF(8021Q,802.1Q)
80__PF(8021AD,802.1ad)
81__PF(MPLS_UC,mpls_uc)
82__PF(MPLS_MC,mpls_mc)
83__PF(TEB,teb)
84
85{ 0x8100, "802.1Q" },
86{ 0x88cc, "LLDP" },
87{ ETH_P_IP, "ipv4" },
88};
89#undef __PF
90
91
92const char * ll_proto_n2a(unsigned short id, char *buf, int len)
93{
94 int i;
95
96 id = ntohs(id);
97
98 for (i=0; !numeric && i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
99 if (llproto_names[i].id == id)
100 return llproto_names[i].name;
101 }
102 snprintf(buf, len, "[%d]", id);
103 return buf;
104}
105
106int ll_proto_a2n(unsigned short *id, const char *buf)
107{
108 int i;
109 for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
110 if (strcasecmp(llproto_names[i].name, buf) == 0) {
111 *id = htons(llproto_names[i].id);
112 return 0;
113 }
114 }
115 if (get_be16(id, buf, 0))
116 return -1;
117 return 0;
118}
119