source: MondoRescue/branches/2.2.9/mindi-busybox/networking/libiproute/ll_proto.c@ 3320

Last change on this file since 3320 was 3320, checked in by Bruno Cornec, 9 years ago
  • Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in the move to 3.0
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 */
10
11#include "libbb.h"
12#include "rt_names.h"
13#include "utils.h"
14
15#if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
16#include <net/ethernet.h>
17#else
18#include <linux/if_ether.h>
19#endif
20
21#if !ENABLE_WERROR
22#warning de-bloat
23#endif
24/* Before re-enabling this, please (1) conditionalize exotic protocols
25 * on CONFIG_something, and (2) decouple strings and numbers
26 * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;)
27 */
28
29#define __PF(f,n) { ETH_P_##f, #n },
30static struct {
31 int id;
32 const char *name;
33} llproto_names[] = {
34__PF(LOOP,loop)
35__PF(PUP,pup)
36#ifdef ETH_P_PUPAT
37__PF(PUPAT,pupat)
38#endif
39__PF(IP,ip)
40__PF(X25,x25)
41__PF(ARP,arp)
42__PF(BPQ,bpq)
43#ifdef ETH_P_IEEEPUP
44__PF(IEEEPUP,ieeepup)
45#endif
46#ifdef ETH_P_IEEEPUPAT
47__PF(IEEEPUPAT,ieeepupat)
48#endif
49__PF(DEC,dec)
50__PF(DNA_DL,dna_dl)
51__PF(DNA_RC,dna_rc)
52__PF(DNA_RT,dna_rt)
53__PF(LAT,lat)
54__PF(DIAG,diag)
55__PF(CUST,cust)
56__PF(SCA,sca)
57__PF(RARP,rarp)
58__PF(ATALK,atalk)
59__PF(AARP,aarp)
60__PF(IPX,ipx)
61__PF(IPV6,ipv6)
62#ifdef ETH_P_PPP_DISC
63__PF(PPP_DISC,ppp_disc)
64#endif
65#ifdef ETH_P_PPP_SES
66__PF(PPP_SES,ppp_ses)
67#endif
68#ifdef ETH_P_ATMMPOA
69__PF(ATMMPOA,atmmpoa)
70#endif
71#ifdef ETH_P_ATMFATE
72__PF(ATMFATE,atmfate)
73#endif
74
75__PF(802_3,802_3)
76__PF(AX25,ax25)
77__PF(ALL,all)
78__PF(802_2,802_2)
79__PF(SNAP,snap)
80__PF(DDCMP,ddcmp)
81__PF(WAN_PPP,wan_ppp)
82__PF(PPP_MP,ppp_mp)
83__PF(LOCALTALK,localtalk)
84__PF(PPPTALK,ppptalk)
85__PF(TR_802_2,tr_802_2)
86__PF(MOBITEX,mobitex)
87__PF(CONTROL,control)
88__PF(IRDA,irda)
89#ifdef ETH_P_ECONET
90__PF(ECONET,econet)
91#endif
92
93{ 0x8100, "802.1Q" },
94{ ETH_P_IP, "ipv4" },
95};
96#undef __PF
97
98
99const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
100{
101 unsigned i;
102 id = ntohs(id);
103 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
104 if (llproto_names[i].id == id)
105 return llproto_names[i].name;
106 }
107 snprintf(buf, len, "[%d]", id);
108 return buf;
109}
110
111int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
112{
113 unsigned i;
114 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
115 if (strcasecmp(llproto_names[i].name, buf) == 0) {
116 i = llproto_names[i].id;
117 goto good;
118 }
119 }
120 i = bb_strtou(buf, NULL, 0);
121 if (errno || i > 0xffff)
122 return -1;
123 good:
124 *id = htons(i);
125 return 0;
126}
Note: See TracBrowser for help on using the repository browser.