diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 15:10:29 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 15:10:29 +0000 |
commit | 53354ac47df03bdccebad66bc22958fa2b4da520 (patch) | |
tree | b3d85b6cd19f81293848235560b24cbce86f77d7 /networking | |
parent | f0d6c255860509b10148c70ef7cb518eb81bea6d (diff) | |
download | busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.tar.gz busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.tar.bz2 busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.zip |
libbb: introduce and use print_flags().
Mostly by Natanael Copa <natanael.copa AT gmail.com>
function old new delta
print_e2flags - 189 +189
print_flags_separated - 86 +86
static.flag_labels - 60 +60
static.dma_wmode_masks - 32 +32
static.flag_masks - 28 +28
static.arp_labels - 16 +16
static.arp_masks - 12 +12
ls_main 836 843 +7
...
popstring 140 134 -6
arp_show 740 708 -32
print_flags 189 25 -164
ipaddr_list_or_flush 2396 2170 -226
process_dev 5306 4706 -600
------------------------------------------------------------------------------
(add/remove: 10/0 grow/shrink: 5/10 up/down: 458/-1043) Total: -585 bytes
text data bss dec hex filename
810564 624 7060 818248 c7c48 busybox_old
810002 624 7060 817686 c7a16 busybox_unstripped
Diffstat (limited to 'networking')
-rw-r--r-- | networking/arp.c | 38 | ||||
-rw-r--r-- | networking/libiproute/ipaddress.c | 19 |
2 files changed, 30 insertions, 27 deletions
diff --git a/networking/arp.c b/networking/arp.c index f42e09f7c..f85a91022 100644 --- a/networking/arp.c +++ b/networking/arp.c | |||
@@ -313,6 +313,26 @@ static void | |||
313 | arp_disp(const char *name, char *ip, int type, int arp_flags, | 313 | arp_disp(const char *name, char *ip, int type, int arp_flags, |
314 | char *hwa, char *mask, char *dev) | 314 | char *hwa, char *mask, char *dev) |
315 | { | 315 | { |
316 | static const int arp_masks[] = { | ||
317 | ATF_PERM, ATF_PUBL, | ||
318 | #ifdef HAVE_ATF_MAGIC | ||
319 | ATF_MAGIC, | ||
320 | #endif | ||
321 | #ifdef HAVE_ATF_DONTPUB | ||
322 | ATF_DONTPUB, | ||
323 | #endif | ||
324 | ATF_USETRAILERS, | ||
325 | }; | ||
326 | static const char arp_labels[] ALIGN1 = "PERM\0""PUP\0" | ||
327 | #ifdef HAVE_ATF_MAGIC | ||
328 | "AUTO\0" | ||
329 | #endif | ||
330 | #ifdef HAVE_ATF_DONTPUB | ||
331 | "DONTPUB\0" | ||
332 | #endif | ||
333 | "TRAIL\0" | ||
334 | ; | ||
335 | |||
316 | const struct hwtype *xhw; | 336 | const struct hwtype *xhw; |
317 | 337 | ||
318 | xhw = get_hwntype(type); | 338 | xhw = get_hwntype(type); |
@@ -333,22 +353,8 @@ arp_disp(const char *name, char *ip, int type, int arp_flags, | |||
333 | if (arp_flags & ATF_NETMASK) | 353 | if (arp_flags & ATF_NETMASK) |
334 | printf("netmask %s ", mask); | 354 | printf("netmask %s ", mask); |
335 | 355 | ||
336 | if (arp_flags & ATF_PERM) | 356 | print_flags_separated(arp_masks, arp_labels, arp_flags, " "); |
337 | printf("PERM "); | 357 | printf(" on %s\n", dev); |
338 | if (arp_flags & ATF_PUBL) | ||
339 | printf("PUP "); | ||
340 | #ifdef HAVE_ATF_MAGIC | ||
341 | if (arp_flags & ATF_MAGIC) | ||
342 | printf("AUTO "); | ||
343 | #endif | ||
344 | #ifdef HAVE_ATF_DONTPUB | ||
345 | if (arp_flags & ATF_DONTPUB) | ||
346 | printf("DONTPUB "); | ||
347 | #endif | ||
348 | if (arp_flags & ATF_USETRAILERS) | ||
349 | printf("TRAIL "); | ||
350 | |||
351 | printf("on %s\n", dev); | ||
352 | } | 358 | } |
353 | 359 | ||
354 | /* Display the contents of the ARP cache in the kernel. */ | 360 | /* Display the contents of the ARP cache in the kernel. */ |
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 07b27870d..faa3f2d06 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -45,16 +45,15 @@ typedef struct filter_t { | |||
45 | 45 | ||
46 | static void print_link_flags(unsigned flags, unsigned mdown) | 46 | static void print_link_flags(unsigned flags, unsigned mdown) |
47 | { | 47 | { |
48 | static const int flag_masks[] = { | ||
49 | IFF_LOOPBACK, IFF_BROADCAST, IFF_POINTOPOINT, | ||
50 | IFF_MULTICAST, IFF_NOARP, IFF_UP, IFF_LOWER_UP }; | ||
51 | static const char flag_labels[] ALIGN1 = | ||
52 | "LOOPBACK\0""BROADCAST\0""POINTOPOINT\0" | ||
53 | "MULTICAST\0""NOARP\0""UP\0""LOWER_UP\0"; | ||
54 | |||
48 | bb_putchar('<'); | 55 | bb_putchar('<'); |
49 | flags &= ~IFF_RUNNING; | 56 | flags &= ~IFF_RUNNING; |
50 | #define _PF(f) if (flags & IFF_##f) { \ | ||
51 | flags &= ~IFF_##f; \ | ||
52 | printf(#f "%s", flags ? "," : ""); } | ||
53 | _PF(LOOPBACK); | ||
54 | _PF(BROADCAST); | ||
55 | _PF(POINTOPOINT); | ||
56 | _PF(MULTICAST); | ||
57 | _PF(NOARP); | ||
58 | #if 0 | 57 | #if 0 |
59 | _PF(ALLMULTI); | 58 | _PF(ALLMULTI); |
60 | _PF(PROMISC); | 59 | _PF(PROMISC); |
@@ -66,9 +65,7 @@ static void print_link_flags(unsigned flags, unsigned mdown) | |||
66 | _PF(PORTSEL); | 65 | _PF(PORTSEL); |
67 | _PF(NOTRAILERS); | 66 | _PF(NOTRAILERS); |
68 | #endif | 67 | #endif |
69 | _PF(UP); | 68 | flags = print_flags_separated(flag_masks, flag_labels, flags, ","); |
70 | _PF(LOWER_UP); | ||
71 | #undef _PF | ||
72 | if (flags) | 69 | if (flags) |
73 | printf("%x", flags); | 70 | printf("%x", flags); |
74 | if (mdown) | 71 | if (mdown) |