blob: 20f26ca3fb9aca37d089663c52092b64afc88c21 [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"
Bernhard Reutner-Fischer9a67ca32006-04-02 21:14:19 +000014
15#include "rt_names.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000016#include "utils.h"
17
Denis Vlasenko83e5d6f2006-12-18 21:49:06 +000018#if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
Eric Andersenfeb283a2003-07-14 08:49:43 +000019#include <net/ethernet.h>
20#else
21#include <linux/if_ether.h>
22#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000023
24#define __PF(f,n) { ETH_P_##f, #n },
25static struct {
26 int id;
27 char *name;
28} llproto_names[] = {
29__PF(LOOP,loop)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000030__PF(PUP,pup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000031#ifdef ETH_P_PUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000032__PF(PUPAT,pupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000033#endif
34__PF(IP,ip)
35__PF(X25,x25)
36__PF(ARP,arp)
37__PF(BPQ,bpq)
38#ifdef ETH_P_IEEEPUP
Eric Andersenc7bda1c2004-03-15 08:29:22 +000039__PF(IEEEPUP,ieeepup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000040#endif
41#ifdef ETH_P_IEEEPUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000042__PF(IEEEPUPAT,ieeepupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000043#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000044__PF(DEC,dec)
45__PF(DNA_DL,dna_dl)
46__PF(DNA_RC,dna_rc)
47__PF(DNA_RT,dna_rt)
48__PF(LAT,lat)
49__PF(DIAG,diag)
50__PF(CUST,cust)
51__PF(SCA,sca)
52__PF(RARP,rarp)
53__PF(ATALK,atalk)
54__PF(AARP,aarp)
55__PF(IPX,ipx)
56__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000057#ifdef ETH_P_PPP_DISC
Eric Andersenc7bda1c2004-03-15 08:29:22 +000058__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000059#endif
60#ifdef ETH_P_PPP_SES
Eric Andersenc7bda1c2004-03-15 08:29:22 +000061__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000062#endif
63#ifdef ETH_P_ATMMPOA
Eric Andersenc7bda1c2004-03-15 08:29:22 +000064__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000065#endif
66#ifdef ETH_P_ATMFATE
Eric Andersenc7bda1c2004-03-15 08:29:22 +000067__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000068#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000069
Eric Andersenc7bda1c2004-03-15 08:29:22 +000070__PF(802_3,802_3)
71__PF(AX25,ax25)
72__PF(ALL,all)
73__PF(802_2,802_2)
74__PF(SNAP,snap)
75__PF(DDCMP,ddcmp)
76__PF(WAN_PPP,wan_ppp)
77__PF(PPP_MP,ppp_mp)
78__PF(LOCALTALK,localtalk)
79__PF(PPPTALK,ppptalk)
80__PF(TR_802_2,tr_802_2)
81__PF(MOBITEX,mobitex)
82__PF(CONTROL,control)
83__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000084#ifdef ETH_P_ECONET
Eric Andersenc7bda1c2004-03-15 08:29:22 +000085__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000086#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000087
88{ 0x8100, "802.1Q" },
89{ ETH_P_IP, "ipv4" },
90};
91#undef __PF
92
93
Eric Andersen14f5c8d2005-04-16 19:39:00 +000094const char * ll_proto_n2a(unsigned short id, char *buf, int len)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000095{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000096 int i;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000097
98 id = ntohs(id);
99
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000100 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
101 if (llproto_names[i].id == id)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000102 return llproto_names[i].name;
103 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000104 snprintf(buf, len, "[%d]", id);
105 return buf;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000106}
107
108int ll_proto_a2n(unsigned short *id, char *buf)
109{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000110 int i;
111 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
112 if (strcasecmp(llproto_names[i].name, buf) == 0) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000113 *id = htons(llproto_names[i].id);
114 return 0;
115 }
116 }
117 if (get_u16(id, buf, 0))
118 return -1;
119 *id = htons(*id);
120 return 0;
121}