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> |
| 15 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 16 | #include <linux/if_arp.h> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 17 | |
| 18 | #include "utils.h" |
| 19 | |
| 20 | |
| 21 | #define __PF(f,n) { ETH_P_##f, #n }, |
| 22 | static struct { |
| 23 | int id; |
| 24 | char *name; |
| 25 | } llproto_names[] = { |
| 26 | __PF(LOOP,loop) |
| 27 | __PF(PUP,pup) |
| 28 | #ifdef ETH_P_PUPAT |
| 29 | __PF(PUPAT,pupat) |
| 30 | #endif |
| 31 | __PF(IP,ip) |
| 32 | __PF(X25,x25) |
| 33 | __PF(ARP,arp) |
| 34 | __PF(BPQ,bpq) |
| 35 | #ifdef ETH_P_IEEEPUP |
| 36 | __PF(IEEEPUP,ieeepup) |
| 37 | #endif |
| 38 | #ifdef ETH_P_IEEEPUPAT |
| 39 | __PF(IEEEPUPAT,ieeepupat) |
| 40 | #endif |
| 41 | __PF(DEC,dec) |
| 42 | __PF(DNA_DL,dna_dl) |
| 43 | __PF(DNA_RC,dna_rc) |
| 44 | __PF(DNA_RT,dna_rt) |
| 45 | __PF(LAT,lat) |
| 46 | __PF(DIAG,diag) |
| 47 | __PF(CUST,cust) |
| 48 | __PF(SCA,sca) |
| 49 | __PF(RARP,rarp) |
| 50 | __PF(ATALK,atalk) |
| 51 | __PF(AARP,aarp) |
| 52 | __PF(IPX,ipx) |
| 53 | __PF(IPV6,ipv6) |
| 54 | __PF(PPP_DISC,ppp_disc) |
| 55 | __PF(PPP_SES,ppp_ses) |
| 56 | __PF(ATMMPOA,atmmpoa) |
| 57 | __PF(ATMFATE,atmfate) |
| 58 | |
| 59 | __PF(802_3,802_3) |
| 60 | __PF(AX25,ax25) |
| 61 | __PF(ALL,all) |
| 62 | __PF(802_2,802_2) |
| 63 | __PF(SNAP,snap) |
| 64 | __PF(DDCMP,ddcmp) |
| 65 | __PF(WAN_PPP,wan_ppp) |
| 66 | __PF(PPP_MP,ppp_mp) |
| 67 | __PF(LOCALTALK,localtalk) |
| 68 | __PF(PPPTALK,ppptalk) |
| 69 | __PF(TR_802_2,tr_802_2) |
| 70 | __PF(MOBITEX,mobitex) |
| 71 | __PF(CONTROL,control) |
| 72 | __PF(IRDA,irda) |
| 73 | __PF(ECONET,econet) |
| 74 | |
| 75 | { 0x8100, "802.1Q" }, |
| 76 | { ETH_P_IP, "ipv4" }, |
| 77 | }; |
| 78 | #undef __PF |
| 79 | |
| 80 | |
| 81 | char * ll_proto_n2a(unsigned short id, char *buf, int len) |
| 82 | { |
| 83 | int i; |
| 84 | |
| 85 | id = ntohs(id); |
| 86 | |
| 87 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
| 88 | if (llproto_names[i].id == id) |
| 89 | return llproto_names[i].name; |
| 90 | } |
| 91 | snprintf(buf, len, "[%d]", id); |
| 92 | return buf; |
| 93 | } |
| 94 | |
| 95 | int ll_proto_a2n(unsigned short *id, char *buf) |
| 96 | { |
| 97 | int i; |
| 98 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
| 99 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
| 100 | *id = htons(llproto_names[i].id); |
| 101 | return 0; |
| 102 | } |
| 103 | } |
| 104 | if (get_u16(id, buf, 0)) |
| 105 | return -1; |
| 106 | *id = htons(*id); |
| 107 | return 0; |
| 108 | } |