11 |
*/ |
*/ |
12 |
|
|
13 |
#include "libbb.h" |
#include "libbb.h" |
|
|
|
14 |
#include "rt_names.h" |
#include "rt_names.h" |
15 |
#include "utils.h" |
#include "utils.h" |
16 |
|
|
20 |
#include <linux/if_ether.h> |
#include <linux/if_ether.h> |
21 |
#endif |
#endif |
22 |
|
|
23 |
|
#if !ENABLE_WERROR |
24 |
|
#warning de-bloat |
25 |
|
#endif |
26 |
|
/* Before re-enabling this, please (1) conditionalize exotic protocols |
27 |
|
* on CONFIG_something, and (2) decouple strings and numbers |
28 |
|
* (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) |
29 |
|
*/ |
30 |
|
|
31 |
#define __PF(f,n) { ETH_P_##f, #n }, |
#define __PF(f,n) { ETH_P_##f, #n }, |
32 |
static struct { |
static struct { |
33 |
int id; |
int id; |
34 |
char *name; |
const char *name; |
35 |
} llproto_names[] = { |
} llproto_names[] = { |
36 |
__PF(LOOP,loop) |
__PF(LOOP,loop) |
37 |
__PF(PUP,pup) |
__PF(PUP,pup) |
98 |
#undef __PF |
#undef __PF |
99 |
|
|
100 |
|
|
101 |
const char * ll_proto_n2a(unsigned short id, char *buf, int len) |
const char *ll_proto_n2a(unsigned short id, char *buf, int len) |
102 |
{ |
{ |
103 |
int i; |
unsigned i; |
|
|
|
104 |
id = ntohs(id); |
id = ntohs(id); |
105 |
|
for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
|
for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
|
106 |
if (llproto_names[i].id == id) |
if (llproto_names[i].id == id) |
107 |
return llproto_names[i].name; |
return llproto_names[i].name; |
108 |
} |
} |
112 |
|
|
113 |
int ll_proto_a2n(unsigned short *id, char *buf) |
int ll_proto_a2n(unsigned short *id, char *buf) |
114 |
{ |
{ |
115 |
int i; |
unsigned i; |
116 |
for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
117 |
if (strcasecmp(llproto_names[i].name, buf) == 0) { |
if (strcasecmp(llproto_names[i].name, buf) == 0) { |
118 |
*id = htons(llproto_names[i].id); |
*id = htons(llproto_names[i].id); |
119 |
return 0; |
return 0; |
124 |
*id = htons(*id); |
*id = htons(*id); |
125 |
return 0; |
return 0; |
126 |
} |
} |
127 |
|
|