]>
Commit | Line | Data |
---|---|---|
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 <fcntl.h> | |
16 | #include <sys/ioctl.h> | |
17 | #include <sys/socket.h> | |
18 | #include <netinet/in.h> | |
19 | #include <arpa/inet.h> | |
20 | #include <string.h> | |
21 | ||
22 | #include <linux/netdevice.h> | |
23 | #include <linux/if_arp.h> | |
24 | #include <linux/sockios.h> | |
25 | ||
26 | #include "utils.h" | |
27 | #include "rt_names.h" | |
28 | ||
29 | ||
30 | #define __PF(f,n) { ETH_P_##f, #n }, | |
31 | static const struct { | |
32 | int id; | |
33 | const char *name; | |
34 | } llproto_names[] = { | |
35 | __PF(LOOP,loop) | |
36 | __PF(PUP,pup) | |
37 | __PF(PUPAT,pupat) | |
38 | __PF(IP,ip) | |
39 | __PF(X25,x25) | |
40 | __PF(ARP,arp) | |
41 | __PF(BPQ,bpq) | |
42 | __PF(IEEEPUP,ieeepup) | |
43 | __PF(IEEEPUPAT,ieeepupat) | |
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) | |
57 | __PF(PPP_DISC,ppp_disc) | |
58 | __PF(PPP_SES,ppp_ses) | |
59 | __PF(ATMMPOA,atmmpoa) | |
60 | __PF(ATMFATE,atmfate) | |
61 | __PF(802_3,802_3) | |
62 | __PF(AX25,ax25) | |
63 | __PF(ALL,all) | |
64 | __PF(802_2,802_2) | |
65 | __PF(SNAP,snap) | |
66 | __PF(DDCMP,ddcmp) | |
67 | __PF(WAN_PPP,wan_ppp) | |
68 | __PF(PPP_MP,ppp_mp) | |
69 | __PF(LOCALTALK,localtalk) | |
70 | __PF(CAN,can) | |
71 | __PF(PPPTALK,ppptalk) | |
72 | __PF(TR_802_2,tr_802_2) | |
73 | __PF(MOBITEX,mobitex) | |
74 | __PF(CONTROL,control) | |
75 | __PF(IRDA,irda) | |
76 | __PF(ECONET,econet) | |
77 | __PF(TIPC,tipc) | |
78 | __PF(AOE,aoe) | |
79 | __PF(8021Q,802.1Q) | |
80 | __PF(8021AD,802.1ad) | |
81 | ||
82 | { 0x8100, "802.1Q" }, | |
83 | { 0x88cc, "LLDP" }, | |
84 | { ETH_P_IP, "ipv4" }, | |
85 | }; | |
86 | #undef __PF | |
87 | ||
88 | ||
89 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) | |
90 | { | |
91 | int i; | |
92 | ||
93 | id = ntohs(id); | |
94 | ||
95 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | |
96 | if (llproto_names[i].id == id) | |
97 | return llproto_names[i].name; | |
98 | } | |
99 | snprintf(buf, len, "[%d]", id); | |
100 | return buf; | |
101 | } | |
102 | ||
103 | int ll_proto_a2n(unsigned short *id, const char *buf) | |
104 | { | |
105 | int i; | |
106 | for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | |
107 | if (strcasecmp(llproto_names[i].name, buf) == 0) { | |
108 | *id = htons(llproto_names[i].id); | |
109 | return 0; | |
110 | } | |
111 | } | |
112 | if (get_be16(id, buf, 0)) | |
113 | return -1; | |
114 | return 0; | |
115 | } |