source: branches/stable/mindi-busybox/networking/libiproute/ll_proto.c @ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 14 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 2.2 KB
Line 
1/*
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 "libbb.h"
13#include <string.h>
14
15#include "rt_names.h"
16#include "utils.h"
17
18#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
19#include <net/ethernet.h>
20#else
21#include <linux/if_ether.h>
22#endif
23
24#define __PF(f,n) { ETH_P_##f, #n },
25static struct {
26    int id;
27    char *name;
28} llproto_names[] = {
29__PF(LOOP,loop)
30__PF(PUP,pup)
31#ifdef ETH_P_PUPAT
32__PF(PUPAT,pupat)
33#endif
34__PF(IP,ip)
35__PF(X25,x25)
36__PF(ARP,arp)
37__PF(BPQ,bpq)
38#ifdef ETH_P_IEEEPUP
39__PF(IEEEPUP,ieeepup)
40#endif
41#ifdef ETH_P_IEEEPUPAT
42__PF(IEEEPUPAT,ieeepupat)
43#endif
44__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)
57#ifdef ETH_P_PPP_DISC
58__PF(PPP_DISC,ppp_disc)
59#endif
60#ifdef ETH_P_PPP_SES
61__PF(PPP_SES,ppp_ses)
62#endif
63#ifdef ETH_P_ATMMPOA
64__PF(ATMMPOA,atmmpoa)
65#endif
66#ifdef ETH_P_ATMFATE
67__PF(ATMFATE,atmfate)
68#endif
69
70__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)
84#ifdef ETH_P_ECONET
85__PF(ECONET,econet)
86#endif
87
88{ 0x8100, "802.1Q" },
89{ ETH_P_IP, "ipv4" },
90};
91#undef __PF
92
93
94const char * ll_proto_n2a(unsigned short id, char *buf, int len)
95{
96    int i;
97
98    id = ntohs(id);
99
100    for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
101         if (llproto_names[i].id == id)
102            return llproto_names[i].name;
103    }
104    snprintf(buf, len, "[%d]", id);
105    return buf;
106}
107
108int ll_proto_a2n(unsigned short *id, char *buf)
109{
110    int i;
111    for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
112         if (strcasecmp(llproto_names[i].name, buf) == 0) {
113             *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}
Note: See TracBrowser for help on using the repository browser.