blob: cfdb34e38c0e8557c8a9ded193deecc0a4c22ea5 [file] [log] [blame]
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00001/*
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>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000013#include <arpa/inet.h>
14#include <string.h>
15
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000016#include <linux/if_arp.h>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000017
18#include "utils.h"
19
20
21#define __PF(f,n) { ETH_P_##f, #n },
22static struct {
23 int id;
24 char *name;
25} llproto_names[] = {
26__PF(LOOP,loop)
27__PF(PUP,pup)
28#ifdef ETH_P_PUPAT
29__PF(PUPAT,pupat)
30#endif
31__PF(IP,ip)
32__PF(X25,x25)
33__PF(ARP,arp)
34__PF(BPQ,bpq)
35#ifdef ETH_P_IEEEPUP
36__PF(IEEEPUP,ieeepup)
37#endif
38#ifdef ETH_P_IEEEPUPAT
39__PF(IEEEPUPAT,ieeepupat)
40#endif
41__PF(DEC,dec)
42__PF(DNA_DL,dna_dl)
43__PF(DNA_RC,dna_rc)
44__PF(DNA_RT,dna_rt)
45__PF(LAT,lat)
46__PF(DIAG,diag)
47__PF(CUST,cust)
48__PF(SCA,sca)
49__PF(RARP,rarp)
50__PF(ATALK,atalk)
51__PF(AARP,aarp)
52__PF(IPX,ipx)
53__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000054#ifdef ETH_P_PPP_DISC
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000055__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000056#endif
57#ifdef ETH_P_PPP_SES
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000058__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000059#endif
60#ifdef ETH_P_ATMMPOA
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000061__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000062#endif
63#ifdef ETH_P_ATMFATE
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000064__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000065#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000066
67__PF(802_3,802_3)
68__PF(AX25,ax25)
69__PF(ALL,all)
70__PF(802_2,802_2)
71__PF(SNAP,snap)
72__PF(DDCMP,ddcmp)
73__PF(WAN_PPP,wan_ppp)
74__PF(PPP_MP,ppp_mp)
75__PF(LOCALTALK,localtalk)
76__PF(PPPTALK,ppptalk)
77__PF(TR_802_2,tr_802_2)
78__PF(MOBITEX,mobitex)
79__PF(CONTROL,control)
80__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000081#ifdef ETH_P_ECONET
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000082__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000083#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000084
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}