]> git.proxmox.com Git - mirror_iproute2.git/blob - lib/ll_proto.c
(Logical change 1.3)
[mirror_iproute2.git] / lib / ll_proto.c
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 <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/sockios.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #include <string.h>
26
27 #include "utils.h"
28
29
30 #define __PF(f,n) { ETH_P_##f, #n },
31 static struct {
32 int id;
33 char *name;
34 } llproto_names[] = {
35 __PF(LOOP,loop)
36 __PF(PUP,pup)
37 #ifdef ETH_P_PUPAT
38 __PF(PUPAT,pupat)
39 #endif
40 __PF(IP,ip)
41 __PF(X25,x25)
42 __PF(ARP,arp)
43 __PF(BPQ,bpq)
44 #ifdef ETH_P_IEEEPUP
45 __PF(IEEEPUP,ieeepup)
46 #endif
47 #ifdef ETH_P_IEEEPUPAT
48 __PF(IEEEPUPAT,ieeepupat)
49 #endif
50 __PF(DEC,dec)
51 __PF(DNA_DL,dna_dl)
52 __PF(DNA_RC,dna_rc)
53 __PF(DNA_RT,dna_rt)
54 __PF(LAT,lat)
55 __PF(DIAG,diag)
56 __PF(CUST,cust)
57 __PF(SCA,sca)
58 __PF(RARP,rarp)
59 __PF(ATALK,atalk)
60 __PF(AARP,aarp)
61 __PF(IPX,ipx)
62 __PF(IPV6,ipv6)
63 #ifdef ETH_P_PPP_DISC
64 __PF(PPP_DISC,ppp_disc)
65 #endif
66 #ifdef ETH_P_PPP_SES
67 __PF(PPP_SES,ppp_ses)
68 #endif
69 #ifdef ETH_P_ATMMPOA
70 __PF(ATMMPOA,atmmpoa)
71 #endif
72 #ifdef ETH_P_ATMFATE
73 __PF(ATMFATE,atmfate)
74 #endif
75
76 __PF(802_3,802_3)
77 __PF(AX25,ax25)
78 __PF(ALL,all)
79 __PF(802_2,802_2)
80 __PF(SNAP,snap)
81 __PF(DDCMP,ddcmp)
82 __PF(WAN_PPP,wan_ppp)
83 __PF(PPP_MP,ppp_mp)
84 __PF(LOCALTALK,localtalk)
85 __PF(PPPTALK,ppptalk)
86 __PF(TR_802_2,tr_802_2)
87 __PF(MOBITEX,mobitex)
88 __PF(CONTROL,control)
89 __PF(IRDA,irda)
90 #ifdef ETH_P_ECONET
91 __PF(ECONET,econet)
92 #endif
93
94 { 0x8100, "802.1Q" },
95 { ETH_P_IP, "ipv4" },
96 };
97 #undef __PF
98
99
100 char * ll_proto_n2a(unsigned short id, char *buf, int len)
101 {
102 int i;
103
104 id = ntohs(id);
105
106 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
107 if (llproto_names[i].id == id)
108 return llproto_names[i].name;
109 }
110 snprintf(buf, len, "[%d]", id);
111 return buf;
112 }
113
114 int ll_proto_a2n(unsigned short *id, char *buf)
115 {
116 int i;
117 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
118 if (strcasecmp(llproto_names[i].name, buf) == 0) {
119 *id = htons(llproto_names[i].id);
120 return 0;
121 }
122 }
123 if (get_u16(id, buf, 0))
124 return -1;
125 *id = htons(*id);
126 return 0;
127 }