]> git.proxmox.com Git - mirror_iproute2.git/blame - lib/ll_proto.c
(Logical change 1.3)
[mirror_iproute2.git] / lib / ll_proto.c
CommitLineData
aba5acdf
SH
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 },
31static 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
100char * 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
114int 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}