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