]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
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 <stdlib.h> | |
14 | #include <unistd.h> | |
15 | #include <syslog.h> | |
16 | #include <fcntl.h> | |
17 | #include <sys/ioctl.h> | |
18 | #include <sys/socket.h> | |
19 | #include <sys/ioctl.h> | |
aba5acdf SH |
20 | #include <netinet/in.h> |
21 | #include <arpa/inet.h> | |
22 | #include <string.h> | |
23 | ||
ea7436fb SH |
24 | #include <linux/netdevice.h> |
25 | #include <linux/if_arp.h> | |
26 | #include <linux/sockios.h> | |
27 | ||
aba5acdf | 28 | #include "utils.h" |
ea7436fb | 29 | #include "rt_names.h" |
aba5acdf SH |
30 | |
31 | ||
32 | #define __PF(f,n) { ETH_P_##f, #n }, | |
33 | static struct { | |
34 | int id; | |
ea7436fb | 35 | const char *name; |
aba5acdf SH |
36 | } llproto_names[] = { |
37 | __PF(LOOP,loop) | |
ae665a52 | 38 | __PF(PUP,pup) |
aba5acdf SH |
39 | #ifdef ETH_P_PUPAT |
40 | __PF(PUPAT,pupat) | |
ae665a52 | 41 | #endif |
aba5acdf SH |
42 | __PF(IP,ip) |
43 | __PF(X25,x25) | |
44 | __PF(ARP,arp) | |
45 | __PF(BPQ,bpq) | |
46 | #ifdef ETH_P_IEEEPUP | |
47 | __PF(IEEEPUP,ieeepup) | |
ae665a52 | 48 | #endif |
aba5acdf SH |
49 | #ifdef ETH_P_IEEEPUPAT |
50 | __PF(IEEEPUPAT,ieeepupat) | |
ae665a52 SH |
51 | #endif |
52 | __PF(DEC,dec) | |
53 | __PF(DNA_DL,dna_dl) | |
54 | __PF(DNA_RC,dna_rc) | |
55 | __PF(DNA_RT,dna_rt) | |
56 | __PF(LAT,lat) | |
57 | __PF(DIAG,diag) | |
58 | __PF(CUST,cust) | |
59 | __PF(SCA,sca) | |
60 | __PF(RARP,rarp) | |
61 | __PF(ATALK,atalk) | |
62 | __PF(AARP,aarp) | |
63 | __PF(IPX,ipx) | |
64 | __PF(IPV6,ipv6) | |
aba5acdf SH |
65 | #ifdef ETH_P_PPP_DISC |
66 | __PF(PPP_DISC,ppp_disc) | |
ae665a52 | 67 | #endif |
aba5acdf SH |
68 | #ifdef ETH_P_PPP_SES |
69 | __PF(PPP_SES,ppp_ses) | |
ae665a52 | 70 | #endif |
aba5acdf SH |
71 | #ifdef ETH_P_ATMMPOA |
72 | __PF(ATMMPOA,atmmpoa) | |
73 | #endif | |
74 | #ifdef ETH_P_ATMFATE | |
75 | __PF(ATMFATE,atmfate) | |
ae665a52 | 76 | #endif |
aba5acdf | 77 | |
ae665a52 SH |
78 | __PF(802_3,802_3) |
79 | __PF(AX25,ax25) | |
80 | __PF(ALL,all) | |
81 | __PF(802_2,802_2) | |
82 | __PF(SNAP,snap) | |
83 | __PF(DDCMP,ddcmp) | |
84 | __PF(WAN_PPP,wan_ppp) | |
85 | __PF(PPP_MP,ppp_mp) | |
86 | __PF(LOCALTALK,localtalk) | |
87 | __PF(PPPTALK,ppptalk) | |
88 | __PF(TR_802_2,tr_802_2) | |
89 | __PF(MOBITEX,mobitex) | |
90 | __PF(CONTROL,control) | |
91 | __PF(IRDA,irda) | |
aba5acdf SH |
92 | #ifdef ETH_P_ECONET |
93 | __PF(ECONET,econet) | |
ae665a52 | 94 | #endif |
aba5acdf SH |
95 | |
96 | { 0x8100, "802.1Q" }, | |
97 | { ETH_P_IP, "ipv4" }, | |
98 | }; | |
99 | #undef __PF | |
100 | ||
101 | ||
ea7436fb | 102 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) |
aba5acdf SH |
103 | { |
104 | int i; | |
105 | ||
106 | id = ntohs(id); | |
107 | ||
108 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | |
109 | if (llproto_names[i].id == id) | |
110 | return llproto_names[i].name; | |
111 | } | |
112 | snprintf(buf, len, "[%d]", id); | |
113 | return buf; | |
114 | } | |
115 | ||
116 | int ll_proto_a2n(unsigned short *id, char *buf) | |
117 | { | |
118 | int i; | |
119 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | |
120 | if (strcasecmp(llproto_names[i].name, buf) == 0) { | |
121 | *id = htons(llproto_names[i].id); | |
122 | return 0; | |
123 | } | |
124 | } | |
125 | if (get_u16(id, buf, 0)) | |
126 | return -1; | |
127 | *id = htons(*id); | |
128 | return 0; | |
129 | } |