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

Last change on this file since 2142 was 1765, checked in by Bruno Cornec, 17 years ago

Update to busybox 1.7.2

File size: 2.2 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
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
13#include "libbb.h"
14#include "rt_names.h"
15#include "utils.h"
16
17#if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
18#include <net/ethernet.h>
19#else
20#include <linux/if_ether.h>
21#endif
22
23#define __PF(f,n) { ETH_P_##f, #n },
24static struct {
25 int id;
26 const char *name;
27} llproto_names[] = {
28__PF(LOOP,loop)
29__PF(PUP,pup)
30#ifdef ETH_P_PUPAT
31__PF(PUPAT,pupat)
32#endif
33__PF(IP,ip)
34__PF(X25,x25)
35__PF(ARP,arp)
36__PF(BPQ,bpq)
37#ifdef ETH_P_IEEEPUP
38__PF(IEEEPUP,ieeepup)
39#endif
40#ifdef ETH_P_IEEEPUPAT
41__PF(IEEEPUPAT,ieeepupat)
42#endif
43__PF(DEC,dec)
44__PF(DNA_DL,dna_dl)
45__PF(DNA_RC,dna_rc)
46__PF(DNA_RT,dna_rt)
47__PF(LAT,lat)
48__PF(DIAG,diag)
49__PF(CUST,cust)
50__PF(SCA,sca)
51__PF(RARP,rarp)
52__PF(ATALK,atalk)
53__PF(AARP,aarp)
54__PF(IPX,ipx)
55__PF(IPV6,ipv6)
56#ifdef ETH_P_PPP_DISC
57__PF(PPP_DISC,ppp_disc)
58#endif
59#ifdef ETH_P_PPP_SES
60__PF(PPP_SES,ppp_ses)
61#endif
62#ifdef ETH_P_ATMMPOA
63__PF(ATMMPOA,atmmpoa)
64#endif
65#ifdef ETH_P_ATMFATE
66__PF(ATMFATE,atmfate)
67#endif
68
69__PF(802_3,802_3)
70__PF(AX25,ax25)
71__PF(ALL,all)
72__PF(802_2,802_2)
73__PF(SNAP,snap)
74__PF(DDCMP,ddcmp)
75__PF(WAN_PPP,wan_ppp)
76__PF(PPP_MP,ppp_mp)
77__PF(LOCALTALK,localtalk)
78__PF(PPPTALK,ppptalk)
79__PF(TR_802_2,tr_802_2)
80__PF(MOBITEX,mobitex)
81__PF(CONTROL,control)
82__PF(IRDA,irda)
83#ifdef ETH_P_ECONET
84__PF(ECONET,econet)
85#endif
86
87{ 0x8100, "802.1Q" },
88{ ETH_P_IP, "ipv4" },
89};
90#undef __PF
91
92
93const char * ll_proto_n2a(unsigned short id, char *buf, int len)
94{
95 int i;
96
97 id = ntohs(id);
98
99 for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
100 if (llproto_names[i].id == id)
101 return llproto_names[i].name;
102 }
103 snprintf(buf, len, "[%d]", id);
104 return buf;
105}
106
107int ll_proto_a2n(unsigned short *id, char *buf)
108{
109 int i;
110 for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
111 if (strcasecmp(llproto_names[i].name, buf) == 0) {
112 *id = htons(llproto_names[i].id);
113 return 0;
114 }
115 }
116 if (get_u16(id, buf, 0))
117 return -1;
118 *id = htons(*id);
119 return 0;
120}
Note: See TracBrowser for help on using the repository browser.