blob: f026ab7e6202b0fd1ce170922064d49da12c3b65 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00002/*
3 * ll_proto.c
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 */
12
Rob Landleyea224be2006-06-18 20:20:07 +000013#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000014#include <string.h>
Bernhard Reutner-Fischer9a67ca32006-04-02 21:14:19 +000015
16#include "rt_names.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000017#include "utils.h"
18
Eric Andersenfeb283a2003-07-14 08:49:43 +000019#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
20#include <net/ethernet.h>
21#else
22#include <linux/if_ether.h>
23#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000024
25#define __PF(f,n) { ETH_P_##f, #n },
26static struct {
27 int id;
28 char *name;
29} llproto_names[] = {
30__PF(LOOP,loop)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000031__PF(PUP,pup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032#ifdef ETH_P_PUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000033__PF(PUPAT,pupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034#endif
35__PF(IP,ip)
36__PF(X25,x25)
37__PF(ARP,arp)
38__PF(BPQ,bpq)
39#ifdef ETH_P_IEEEPUP
Eric Andersenc7bda1c2004-03-15 08:29:22 +000040__PF(IEEEPUP,ieeepup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000041#endif
42#ifdef ETH_P_IEEEPUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000043__PF(IEEEPUPAT,ieeepupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000044#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000045__PF(DEC,dec)
46__PF(DNA_DL,dna_dl)
47__PF(DNA_RC,dna_rc)
48__PF(DNA_RT,dna_rt)
49__PF(LAT,lat)
50__PF(DIAG,diag)
51__PF(CUST,cust)
52__PF(SCA,sca)
53__PF(RARP,rarp)
54__PF(ATALK,atalk)
55__PF(AARP,aarp)
56__PF(IPX,ipx)
57__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000058#ifdef ETH_P_PPP_DISC
Eric Andersenc7bda1c2004-03-15 08:29:22 +000059__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000060#endif
61#ifdef ETH_P_PPP_SES
Eric Andersenc7bda1c2004-03-15 08:29:22 +000062__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000063#endif
64#ifdef ETH_P_ATMMPOA
Eric Andersenc7bda1c2004-03-15 08:29:22 +000065__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000066#endif
67#ifdef ETH_P_ATMFATE
Eric Andersenc7bda1c2004-03-15 08:29:22 +000068__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000069#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000070
Eric Andersenc7bda1c2004-03-15 08:29:22 +000071__PF(802_3,802_3)
72__PF(AX25,ax25)
73__PF(ALL,all)
74__PF(802_2,802_2)
75__PF(SNAP,snap)
76__PF(DDCMP,ddcmp)
77__PF(WAN_PPP,wan_ppp)
78__PF(PPP_MP,ppp_mp)
79__PF(LOCALTALK,localtalk)
80__PF(PPPTALK,ppptalk)
81__PF(TR_802_2,tr_802_2)
82__PF(MOBITEX,mobitex)
83__PF(CONTROL,control)
84__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000085#ifdef ETH_P_ECONET
Eric Andersenc7bda1c2004-03-15 08:29:22 +000086__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000087#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000088
89{ 0x8100, "802.1Q" },
90{ ETH_P_IP, "ipv4" },
91};
92#undef __PF
93
94
Eric Andersen14f5c8d2005-04-16 19:39:00 +000095const char * ll_proto_n2a(unsigned short id, char *buf, int len)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000096{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000097 int i;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000098
99 id = ntohs(id);
100
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000101 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
102 if (llproto_names[i].id == id)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000103 return llproto_names[i].name;
104 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000105 snprintf(buf, len, "[%d]", id);
106 return buf;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000107}
108
109int ll_proto_a2n(unsigned short *id, char *buf)
110{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000111 int i;
112 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
113 if (strcasecmp(llproto_names[i].name, buf) == 0) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000114 *id = htons(llproto_names[i].id);
115 return 0;
116 }
117 }
118 if (get_u16(id, buf, 0))
119 return -1;
120 *id = htons(*id);
121 return 0;
122}