"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 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 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 13 | #include "libbb.h" |
Bernhard Reutner-Fischer | 9a67ca3 | 2006-04-02 21:14:19 +0000 | [diff] [blame] | 14 | |
| 15 | #include "rt_names.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 16 | #include "utils.h" |
| 17 | |
Denis Vlasenko | 83e5d6f | 2006-12-18 21:49:06 +0000 | [diff] [blame] | 18 | #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 |
Eric Andersen | feb283a | 2003-07-14 08:49:43 +0000 | [diff] [blame] | 19 | #include <net/ethernet.h> |
| 20 | #else |
| 21 | #include <linux/if_ether.h> |
| 22 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 23 | |
| 24 | #define __PF(f,n) { ETH_P_##f, #n }, |
| 25 | static struct { |
| 26 | int id; |
| 27 | char *name; |
| 28 | } llproto_names[] = { |
| 29 | __PF(LOOP,loop) |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 30 | __PF(PUP,pup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 31 | #ifdef ETH_P_PUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 32 | __PF(PUPAT,pupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 33 | #endif |
| 34 | __PF(IP,ip) |
| 35 | __PF(X25,x25) |
| 36 | __PF(ARP,arp) |
| 37 | __PF(BPQ,bpq) |
| 38 | #ifdef ETH_P_IEEEPUP |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 39 | __PF(IEEEPUP,ieeepup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 40 | #endif |
| 41 | #ifdef ETH_P_IEEEPUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 42 | __PF(IEEEPUPAT,ieeepupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 43 | #endif |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 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) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 57 | #ifdef ETH_P_PPP_DISC |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 58 | __PF(PPP_DISC,ppp_disc) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 59 | #endif |
| 60 | #ifdef ETH_P_PPP_SES |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 61 | __PF(PPP_SES,ppp_ses) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 62 | #endif |
| 63 | #ifdef ETH_P_ATMMPOA |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 64 | __PF(ATMMPOA,atmmpoa) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 65 | #endif |
| 66 | #ifdef ETH_P_ATMFATE |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 67 | __PF(ATMFATE,atmfate) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 68 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 69 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 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) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 84 | #ifdef ETH_P_ECONET |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 85 | __PF(ECONET,econet) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 86 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 87 | |
| 88 | { 0x8100, "802.1Q" }, |
| 89 | { ETH_P_IP, "ipv4" }, |
| 90 | }; |
| 91 | #undef __PF |
| 92 | |
| 93 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 94 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 95 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 96 | int i; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 97 | |
| 98 | id = ntohs(id); |
| 99 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 100 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
| 101 | if (llproto_names[i].id == id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 102 | return llproto_names[i].name; |
| 103 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 104 | snprintf(buf, len, "[%d]", id); |
| 105 | return buf; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | int ll_proto_a2n(unsigned short *id, char *buf) |
| 109 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 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) { |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 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 | } |