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