aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/ll_proto.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/ll_proto.c')
-rw-r--r--networking/libiproute/ll_proto.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c
new file mode 100644
index 000000000..394338aea
--- /dev/null
+++ b/networking/libiproute/ll_proto.c
@@ -0,0 +1,118 @@
1/*
2 * ll_proto.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#include "utils.h"
29
30
31#define __PF(f,n) { ETH_P_##f, #n },
32static struct {
33 int id;
34 char *name;
35} llproto_names[] = {
36__PF(LOOP,loop)
37__PF(PUP,pup)
38#ifdef ETH_P_PUPAT
39__PF(PUPAT,pupat)
40#endif
41__PF(IP,ip)
42__PF(X25,x25)
43__PF(ARP,arp)
44__PF(BPQ,bpq)
45#ifdef ETH_P_IEEEPUP
46__PF(IEEEPUP,ieeepup)
47#endif
48#ifdef ETH_P_IEEEPUPAT
49__PF(IEEEPUPAT,ieeepupat)
50#endif
51__PF(DEC,dec)
52__PF(DNA_DL,dna_dl)
53__PF(DNA_RC,dna_rc)
54__PF(DNA_RT,dna_rt)
55__PF(LAT,lat)
56__PF(DIAG,diag)
57__PF(CUST,cust)
58__PF(SCA,sca)
59__PF(RARP,rarp)
60__PF(ATALK,atalk)
61__PF(AARP,aarp)
62__PF(IPX,ipx)
63__PF(IPV6,ipv6)
64__PF(PPP_DISC,ppp_disc)
65__PF(PPP_SES,ppp_ses)
66__PF(ATMMPOA,atmmpoa)
67__PF(ATMFATE,atmfate)
68
69__PF(802_3,802_3)
70__PF(AX25,ax25)
71__PF(ALL,all)
72__PF(802_2,802_2)
73__PF(SNAP,snap)
74__PF(DDCMP,ddcmp)
75__PF(WAN_PPP,wan_ppp)
76__PF(PPP_MP,ppp_mp)
77__PF(LOCALTALK,localtalk)
78__PF(PPPTALK,ppptalk)
79__PF(TR_802_2,tr_802_2)
80__PF(MOBITEX,mobitex)
81__PF(CONTROL,control)
82__PF(IRDA,irda)
83__PF(ECONET,econet)
84
85{ 0x8100, "802.1Q" },
86{ ETH_P_IP, "ipv4" },
87};
88#undef __PF
89
90
91char * ll_proto_n2a(unsigned short id, char *buf, int len)
92{
93 int i;
94
95 id = ntohs(id);
96
97 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
98 if (llproto_names[i].id == id)
99 return llproto_names[i].name;
100 }
101 snprintf(buf, len, "[%d]", id);
102 return buf;
103}
104
105int ll_proto_a2n(unsigned short *id, char *buf)
106{
107 int i;
108 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
109 if (strcasecmp(llproto_names[i].name, buf) == 0) {
110 *id = htons(llproto_names[i].id);
111 return 0;
112 }
113 }
114 if (get_u16(id, buf, 0))
115 return -1;
116 *id = htons(*id);
117 return 0;
118}