Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 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> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 13 | #include <arpa/inet.h> |
| 14 | #include <string.h> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 15 | #include "utils.h" |
| 16 | |
Eric Andersen | feb283a | 2003-07-14 08:49:43 +0000 | [diff] [blame] | 17 | #if __GLIBC__ >=2 && __GLIBC_MINOR >= 1 |
| 18 | #include <net/ethernet.h> |
| 19 | #else |
| 20 | #include <linux/if_ether.h> |
| 21 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 22 | |
| 23 | #define __PF(f,n) { ETH_P_##f, #n }, |
| 24 | static struct { |
| 25 | int id; |
| 26 | char *name; |
| 27 | } llproto_names[] = { |
| 28 | __PF(LOOP,loop) |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 29 | __PF(PUP,pup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 30 | #ifdef ETH_P_PUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 31 | __PF(PUPAT,pupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 32 | #endif |
| 33 | __PF(IP,ip) |
| 34 | __PF(X25,x25) |
| 35 | __PF(ARP,arp) |
| 36 | __PF(BPQ,bpq) |
| 37 | #ifdef ETH_P_IEEEPUP |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 38 | __PF(IEEEPUP,ieeepup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 39 | #endif |
| 40 | #ifdef ETH_P_IEEEPUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 41 | __PF(IEEEPUPAT,ieeepupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 42 | #endif |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 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) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 56 | #ifdef ETH_P_PPP_DISC |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 57 | __PF(PPP_DISC,ppp_disc) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 58 | #endif |
| 59 | #ifdef ETH_P_PPP_SES |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 60 | __PF(PPP_SES,ppp_ses) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 61 | #endif |
| 62 | #ifdef ETH_P_ATMMPOA |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 63 | __PF(ATMMPOA,atmmpoa) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 64 | #endif |
| 65 | #ifdef ETH_P_ATMFATE |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 66 | __PF(ATMFATE,atmfate) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 67 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 68 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 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) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 83 | #ifdef ETH_P_ECONET |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 84 | __PF(ECONET,econet) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 85 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 86 | |
| 87 | { 0x8100, "802.1Q" }, |
| 88 | { ETH_P_IP, "ipv4" }, |
| 89 | }; |
| 90 | #undef __PF |
| 91 | |
| 92 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 93 | 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] | 94 | { |
| 95 | int i; |
| 96 | |
| 97 | id = ntohs(id); |
| 98 | |
| 99 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); 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 | |
| 107 | int ll_proto_a2n(unsigned short *id, char *buf) |
| 108 | { |
| 109 | int i; |
| 110 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); 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 | } |