source: MondoRescue/branches/2.2.9/mindi-busybox/networking/libiproute/rtm_map.c@ 2887

Last change on this file since 2887 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 2.5 KB
RevLine 
[1765]1/* vi: set sw=4 ts=4: */
[821]2/*
[2725]3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
[821]7 *
[2725]8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
[821]9 */
10
[1765]11#include "libbb.h"
[821]12#include "rt_names.h"
13#include "utils.h"
14
[2725]15const char* FAST_FUNC rtnl_rtntype_n2a(int id, char *buf)
[821]16{
17 switch (id) {
18 case RTN_UNSPEC:
19 return "none";
20 case RTN_UNICAST:
21 return "unicast";
22 case RTN_LOCAL:
23 return "local";
24 case RTN_BROADCAST:
25 return "broadcast";
26 case RTN_ANYCAST:
27 return "anycast";
28 case RTN_MULTICAST:
29 return "multicast";
30 case RTN_BLACKHOLE:
31 return "blackhole";
32 case RTN_UNREACHABLE:
33 return "unreachable";
34 case RTN_PROHIBIT:
35 return "prohibit";
36 case RTN_THROW:
37 return "throw";
38 case RTN_NAT:
39 return "nat";
40 case RTN_XRESOLVE:
41 return "xresolve";
42 default:
[2725]43 /* buf is SPRINT_BSIZE big */
44 sprintf(buf, "%d", id);
[821]45 return buf;
46 }
47}
48
49
[2725]50int FAST_FUNC rtnl_rtntype_a2n(int *id, char *arg)
[821]51{
[1765]52 static const char keywords[] ALIGN1 =
53 "local\0""nat\0""broadcast\0""brd\0""anycast\0"
54 "multicast\0""prohibit\0""unreachable\0""blackhole\0"
55 "xresolve\0""unicast\0""throw\0";
56 enum {
57 ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast,
58 ARG_multicast, ARG_prohibit, ARG_unreachable, ARG_blackhole,
59 ARG_xresolve, ARG_unicast, ARG_throw
60 };
61 const smalluint key = index_in_substrings(keywords, arg) + 1;
[821]62 char *end;
63 unsigned long res;
64
[1765]65 if (key == ARG_local)
[821]66 res = RTN_LOCAL;
[1765]67 else if (key == ARG_nat)
[821]68 res = RTN_NAT;
[1765]69 else if (key == ARG_broadcast || key == ARG_brd)
[821]70 res = RTN_BROADCAST;
[1765]71 else if (key == ARG_anycast)
[821]72 res = RTN_ANYCAST;
[1765]73 else if (key == ARG_multicast)
[821]74 res = RTN_MULTICAST;
[1765]75 else if (key == ARG_prohibit)
[821]76 res = RTN_PROHIBIT;
[1765]77 else if (key == ARG_unreachable)
[821]78 res = RTN_UNREACHABLE;
[1765]79 else if (key == ARG_blackhole)
[821]80 res = RTN_BLACKHOLE;
[1765]81 else if (key == ARG_xresolve)
[821]82 res = RTN_XRESOLVE;
[1765]83 else if (key == ARG_unicast)
[821]84 res = RTN_UNICAST;
[1765]85 else if (key == ARG_throw)
[821]86 res = RTN_THROW;
87 else {
88 res = strtoul(arg, &end, 0);
[2725]89 if (end == arg || *end || res > 255)
[821]90 return -1;
91 }
92 *id = res;
93 return 0;
94}
95
[2725]96int FAST_FUNC get_rt_realms(uint32_t *realms, char *arg)
[821]97{
[1765]98 uint32_t realm = 0;
[821]99 char *p = strchr(arg, '/');
100
101 *realms = 0;
102 if (p) {
103 *p = 0;
104 if (rtnl_rtrealm_a2n(realms, arg)) {
105 *p = '/';
106 return -1;
107 }
108 *realms <<= 16;
109 *p = '/';
110 arg = p+1;
111 }
112 if (*arg && rtnl_rtrealm_a2n(&realm, arg))
113 return -1;
114 *realms |= realm;
115 return 0;
116}
Note: See TracBrowser for help on using the repository browser.