aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/libiproute/ipaddress.c105
-rw-r--r--networking/libiproute/iprule.c49
2 files changed, 75 insertions, 79 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index b3cbe3840..4bc87e7b8 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -39,13 +39,13 @@ typedef struct filter_t {
39#define filter (*(filter_t*)&bb_common_bufsiz1) 39#define filter (*(filter_t*)&bb_common_bufsiz1)
40 40
41 41
42static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown) 42static void print_link_flags(unsigned flags, unsigned mdown)
43{ 43{
44 fprintf(fp, "<"); 44 printf("<");
45 flags &= ~IFF_RUNNING; 45 flags &= ~IFF_RUNNING;
46#define _PF(f) if (flags & IFF_##f) { \ 46#define _PF(f) if (flags & IFF_##f) { \
47 flags &= ~IFF_##f; \ 47 flags &= ~IFF_##f; \
48 fprintf(fp, #f "%s", flags ? "," : ""); } 48 printf(#f "%s", flags ? "," : ""); }
49 _PF(LOOPBACK); 49 _PF(LOOPBACK);
50 _PF(BROADCAST); 50 _PF(BROADCAST);
51 _PF(POINTOPOINT); 51 _PF(POINTOPOINT);
@@ -65,10 +65,10 @@ static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown)
65 _PF(UP); 65 _PF(UP);
66#undef _PF 66#undef _PF
67 if (flags) 67 if (flags)
68 fprintf(fp, "%x", flags); 68 printf("%x", flags);
69 if (mdown) 69 if (mdown)
70 fprintf(fp, ",M-DOWN"); 70 printf(",M-DOWN");
71 fprintf(fp, "> "); 71 printf("> ");
72} 72}
73 73
74static void print_queuelen(char *name) 74static void print_queuelen(char *name)
@@ -92,10 +92,8 @@ static void print_queuelen(char *name)
92 printf("qlen %d", ifr.ifr_qlen); 92 printf("qlen %d", ifr.ifr_qlen);
93} 93}
94 94
95static int print_linkinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who, 95static int print_linkinfo(const struct nlmsghdr *n)
96 const struct nlmsghdr *n, void ATTRIBUTE_UNUSED *arg)
97{ 96{
98 FILE *fp = (FILE*)arg;
99 struct ifinfomsg *ifi = NLMSG_DATA(n); 97 struct ifinfomsg *ifi = NLMSG_DATA(n);
100 struct rtattr * tb[IFLA_MAX+1]; 98 struct rtattr * tb[IFLA_MAX+1];
101 int len = n->nlmsg_len; 99 int len = n->nlmsg_len;
@@ -127,34 +125,34 @@ static int print_linkinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
127 } 125 }
128 126
129 if (n->nlmsg_type == RTM_DELLINK) 127 if (n->nlmsg_type == RTM_DELLINK)
130 fprintf(fp, "Deleted "); 128 printf("Deleted ");
131 129
132 fprintf(fp, "%d: %s", ifi->ifi_index, 130 printf("%d: %s", ifi->ifi_index,
133 tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>"); 131 tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>");
134 132
135 if (tb[IFLA_LINK]) { 133 if (tb[IFLA_LINK]) {
136 SPRINT_BUF(b1); 134 SPRINT_BUF(b1);
137 int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); 135 int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
138 if (iflink == 0) 136 if (iflink == 0)
139 fprintf(fp, "@NONE: "); 137 printf("@NONE: ");
140 else { 138 else {
141 fprintf(fp, "@%s: ", ll_idx_n2a(iflink, b1)); 139 printf("@%s: ", ll_idx_n2a(iflink, b1));
142 m_flag = ll_index_to_flags(iflink); 140 m_flag = ll_index_to_flags(iflink);
143 m_flag = !(m_flag & IFF_UP); 141 m_flag = !(m_flag & IFF_UP);
144 } 142 }
145 } else { 143 } else {
146 fprintf(fp, ": "); 144 printf(": ");
147 } 145 }
148 print_link_flags(fp, ifi->ifi_flags, m_flag); 146 print_link_flags(ifi->ifi_flags, m_flag);
149 147
150 if (tb[IFLA_MTU]) 148 if (tb[IFLA_MTU])
151 fprintf(fp, "mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU])); 149 printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
152 if (tb[IFLA_QDISC]) 150 if (tb[IFLA_QDISC])
153 fprintf(fp, "qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC])); 151 printf("qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC]));
154#ifdef IFLA_MASTER 152#ifdef IFLA_MASTER
155 if (tb[IFLA_MASTER]) { 153 if (tb[IFLA_MASTER]) {
156 SPRINT_BUF(b1); 154 SPRINT_BUF(b1);
157 fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); 155 printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1));
158 } 156 }
159#endif 157#endif
160 if (filter.showqueue) 158 if (filter.showqueue)
@@ -162,27 +160,27 @@ static int print_linkinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
162 160
163 if (!filter.family || filter.family == AF_PACKET) { 161 if (!filter.family || filter.family == AF_PACKET) {
164 SPRINT_BUF(b1); 162 SPRINT_BUF(b1);
165 fprintf(fp, "%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1, sizeof(b1))); 163 printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1, sizeof(b1)));
166 164
167 if (tb[IFLA_ADDRESS]) { 165 if (tb[IFLA_ADDRESS]) {
168 fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]), 166 fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
169 RTA_PAYLOAD(tb[IFLA_ADDRESS]), 167 RTA_PAYLOAD(tb[IFLA_ADDRESS]),
170 ifi->ifi_type, 168 ifi->ifi_type,
171 b1, sizeof(b1)), fp); 169 b1, sizeof(b1)), stdout);
172 } 170 }
173 if (tb[IFLA_BROADCAST]) { 171 if (tb[IFLA_BROADCAST]) {
174 if (ifi->ifi_flags & IFF_POINTOPOINT) 172 if (ifi->ifi_flags & IFF_POINTOPOINT)
175 fprintf(fp, " peer "); 173 printf(" peer ");
176 else 174 else
177 fprintf(fp, " brd "); 175 printf(" brd ");
178 fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]), 176 fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
179 RTA_PAYLOAD(tb[IFLA_BROADCAST]), 177 RTA_PAYLOAD(tb[IFLA_BROADCAST]),
180 ifi->ifi_type, 178 ifi->ifi_type,
181 b1, sizeof(b1)), fp); 179 b1, sizeof(b1)), stdout);
182 } 180 }
183 } 181 }
184 fputc('\n', fp); 182 bb_putchar('\n');
185 fflush(fp); 183 /*fflush(stdout);*/
186 return 0; 184 return 0;
187} 185}
188 186
@@ -196,10 +194,9 @@ static int flush_update(void)
196 return 0; 194 return 0;
197} 195}
198 196
199static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who, 197static int print_addrinfo(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
200 struct nlmsghdr *n, void ATTRIBUTE_UNUSED *arg) 198 struct nlmsghdr *n, void *arg ATTRIBUTE_UNUSED)
201{ 199{
202 FILE *fp = (FILE*)arg;
203 struct ifaddrmsg *ifa = NLMSG_DATA(n); 200 struct ifaddrmsg *ifa = NLMSG_DATA(n);
204 int len = n->nlmsg_len; 201 int len = n->nlmsg_len;
205 struct rtattr * rta_tb[IFA_MAX+1]; 202 struct rtattr * rta_tb[IFA_MAX+1];
@@ -268,28 +265,28 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
268 } 265 }
269 266
270 if (n->nlmsg_type == RTM_DELADDR) 267 if (n->nlmsg_type == RTM_DELADDR)
271 fprintf(fp, "Deleted "); 268 printf("Deleted ");
272 269
273 if (filter.oneline) 270 if (filter.oneline)
274 fprintf(fp, "%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index)); 271 printf("%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index));
275 if (ifa->ifa_family == AF_INET) 272 if (ifa->ifa_family == AF_INET)
276 fprintf(fp, " inet "); 273 printf(" inet ");
277 else if (ifa->ifa_family == AF_INET6) 274 else if (ifa->ifa_family == AF_INET6)
278 fprintf(fp, " inet6 "); 275 printf(" inet6 ");
279 else 276 else
280 fprintf(fp, " family %d ", ifa->ifa_family); 277 printf(" family %d ", ifa->ifa_family);
281 278
282 if (rta_tb[IFA_LOCAL]) { 279 if (rta_tb[IFA_LOCAL]) {
283 fputs(rt_addr_n2a(ifa->ifa_family, 280 fputs(rt_addr_n2a(ifa->ifa_family,
284 RTA_PAYLOAD(rta_tb[IFA_LOCAL]), 281 RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
285 RTA_DATA(rta_tb[IFA_LOCAL]), 282 RTA_DATA(rta_tb[IFA_LOCAL]),
286 abuf, sizeof(abuf)), fp); 283 abuf, sizeof(abuf)), stdout);
287 284
288 if (rta_tb[IFA_ADDRESS] == NULL || 285 if (rta_tb[IFA_ADDRESS] == NULL ||
289 memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) { 286 memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) {
290 fprintf(fp, "/%d ", ifa->ifa_prefixlen); 287 printf("/%d ", ifa->ifa_prefixlen);
291 } else { 288 } else {
292 fprintf(fp, " peer %s/%d ", 289 printf(" peer %s/%d ",
293 rt_addr_n2a(ifa->ifa_family, 290 rt_addr_n2a(ifa->ifa_family,
294 RTA_PAYLOAD(rta_tb[IFA_ADDRESS]), 291 RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
295 RTA_DATA(rta_tb[IFA_ADDRESS]), 292 RTA_DATA(rta_tb[IFA_ADDRESS]),
@@ -299,44 +296,44 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
299 } 296 }
300 297
301 if (rta_tb[IFA_BROADCAST]) { 298 if (rta_tb[IFA_BROADCAST]) {
302 fprintf(fp, "brd %s ", 299 printf("brd %s ",
303 rt_addr_n2a(ifa->ifa_family, 300 rt_addr_n2a(ifa->ifa_family,
304 RTA_PAYLOAD(rta_tb[IFA_BROADCAST]), 301 RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
305 RTA_DATA(rta_tb[IFA_BROADCAST]), 302 RTA_DATA(rta_tb[IFA_BROADCAST]),
306 abuf, sizeof(abuf))); 303 abuf, sizeof(abuf)));
307 } 304 }
308 if (rta_tb[IFA_ANYCAST]) { 305 if (rta_tb[IFA_ANYCAST]) {
309 fprintf(fp, "any %s ", 306 printf("any %s ",
310 rt_addr_n2a(ifa->ifa_family, 307 rt_addr_n2a(ifa->ifa_family,
311 RTA_PAYLOAD(rta_tb[IFA_ANYCAST]), 308 RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
312 RTA_DATA(rta_tb[IFA_ANYCAST]), 309 RTA_DATA(rta_tb[IFA_ANYCAST]),
313 abuf, sizeof(abuf))); 310 abuf, sizeof(abuf)));
314 } 311 }
315 fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1))); 312 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
316 if (ifa->ifa_flags & IFA_F_SECONDARY) { 313 if (ifa->ifa_flags & IFA_F_SECONDARY) {
317 ifa->ifa_flags &= ~IFA_F_SECONDARY; 314 ifa->ifa_flags &= ~IFA_F_SECONDARY;
318 fprintf(fp, "secondary "); 315 printf("secondary ");
319 } 316 }
320 if (ifa->ifa_flags & IFA_F_TENTATIVE) { 317 if (ifa->ifa_flags & IFA_F_TENTATIVE) {
321 ifa->ifa_flags &= ~IFA_F_TENTATIVE; 318 ifa->ifa_flags &= ~IFA_F_TENTATIVE;
322 fprintf(fp, "tentative "); 319 printf("tentative ");
323 } 320 }
324 if (ifa->ifa_flags & IFA_F_DEPRECATED) { 321 if (ifa->ifa_flags & IFA_F_DEPRECATED) {
325 ifa->ifa_flags &= ~IFA_F_DEPRECATED; 322 ifa->ifa_flags &= ~IFA_F_DEPRECATED;
326 fprintf(fp, "deprecated "); 323 printf("deprecated ");
327 } 324 }
328 if (!(ifa->ifa_flags & IFA_F_PERMANENT)) { 325 if (!(ifa->ifa_flags & IFA_F_PERMANENT)) {
329 fprintf(fp, "dynamic "); 326 printf("dynamic ");
330 } else 327 } else
331 ifa->ifa_flags &= ~IFA_F_PERMANENT; 328 ifa->ifa_flags &= ~IFA_F_PERMANENT;
332 if (ifa->ifa_flags) 329 if (ifa->ifa_flags)
333 fprintf(fp, "flags %02x ", ifa->ifa_flags); 330 printf("flags %02x ", ifa->ifa_flags);
334 if (rta_tb[IFA_LABEL]) 331 if (rta_tb[IFA_LABEL])
335 fputs((char*)RTA_DATA(rta_tb[IFA_LABEL]), fp); 332 fputs((char*)RTA_DATA(rta_tb[IFA_LABEL]), stdout);
336 if (rta_tb[IFA_CACHEINFO]) { 333 if (rta_tb[IFA_CACHEINFO]) {
337 struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]); 334 struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
338 char buf[128]; 335 char buf[128];
339 fputc(_SL_, fp); 336 bb_putchar(_SL_);
340 if (ci->ifa_valid == 0xFFFFFFFFU) 337 if (ci->ifa_valid == 0xFFFFFFFFU)
341 sprintf(buf, "valid_lft forever"); 338 sprintf(buf, "valid_lft forever");
342 else 339 else
@@ -345,10 +342,10 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
345 sprintf(buf+strlen(buf), " preferred_lft forever"); 342 sprintf(buf+strlen(buf), " preferred_lft forever");
346 else 343 else
347 sprintf(buf+strlen(buf), " preferred_lft %dsec", ci->ifa_prefered); 344 sprintf(buf+strlen(buf), " preferred_lft %dsec", ci->ifa_prefered);
348 fprintf(fp, " %s", buf); 345 printf(" %s", buf);
349 } 346 }
350 fputc('\n', fp); 347 bb_putchar('\n');
351 fflush(fp); 348 /*fflush(stdout);*/
352 return 0; 349 return 0;
353} 350}
354 351
@@ -359,7 +356,7 @@ struct nlmsg_list
359 struct nlmsghdr h; 356 struct nlmsghdr h;
360}; 357};
361 358
362static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp) 359static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo)
363{ 360{
364 for (; ainfo; ainfo = ainfo->next) { 361 for (; ainfo; ainfo = ainfo->next) {
365 struct nlmsghdr *n = &ainfo->h; 362 struct nlmsghdr *n = &ainfo->h;
@@ -375,7 +372,7 @@ static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *
375 (filter.family && filter.family != ifa->ifa_family)) 372 (filter.family && filter.family != ifa->ifa_family))
376 continue; 373 continue;
377 374
378 print_addrinfo(NULL, n, fp); 375 print_addrinfo(NULL, n, NULL);
379 } 376 }
380 return 0; 377 return 0;
381} 378}
@@ -498,7 +495,7 @@ int ipaddr_list_or_flush(char **argv, int flush)
498 for (;;) { 495 for (;;) {
499 xrtnl_wilddump_request(&rth, filter.family, RTM_GETADDR); 496 xrtnl_wilddump_request(&rth, filter.family, RTM_GETADDR);
500 filter.flushed = 0; 497 filter.flushed = 0;
501 xrtnl_dump_filter(&rth, print_addrinfo, stdout); 498 xrtnl_dump_filter(&rth, print_addrinfo, NULL);
502 if (filter.flushed == 0) { 499 if (filter.flushed == 0) {
503 return 0; 500 return 0;
504 } 501 }
@@ -574,10 +571,10 @@ int ipaddr_list_or_flush(char **argv, int flush)
574 } 571 }
575 572
576 for (l = linfo; l; l = l->next) { 573 for (l = linfo; l; l = l->next) {
577 if (no_link || print_linkinfo(NULL, &l->h, stdout) == 0) { 574 if (no_link || print_linkinfo(&l->h) == 0) {
578 struct ifinfomsg *ifi = NLMSG_DATA(&l->h); 575 struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
579 if (filter.family != AF_PACKET) 576 if (filter.family != AF_PACKET)
580 print_selected_addrinfo(ifi->ifi_index, ainfo, stdout); 577 print_selected_addrinfo(ifi->ifi_index, ainfo);
581 } 578 }
582 } 579 }
583 580
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 3f9007ee9..f62429a7c 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -41,9 +41,8 @@ static void usage(void)
41*/ 41*/
42 42
43static int print_rule(struct sockaddr_nl *who ATTRIBUTE_UNUSED, 43static int print_rule(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
44 struct nlmsghdr *n, void *arg) 44 struct nlmsghdr *n, void *arg ATTRIBUTE_UNUSED)
45{ 45{
46 FILE *fp = (FILE*)arg;
47 struct rtmsg *r = NLMSG_DATA(n); 46 struct rtmsg *r = NLMSG_DATA(n);
48 int len = n->nlmsg_len; 47 int len = n->nlmsg_len;
49 int host_len = -1; 48 int host_len = -1;
@@ -71,14 +70,14 @@ static int print_rule(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
71 host_len = 80; 70 host_len = 80;
72*/ 71*/
73 if (tb[RTA_PRIORITY]) 72 if (tb[RTA_PRIORITY])
74 fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY])); 73 printf("%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY]));
75 else 74 else
76 fprintf(fp, "0:\t"); 75 printf("0:\t");
77 76
78 fprintf(fp, "from "); 77 printf("from ");
79 if (tb[RTA_SRC]) { 78 if (tb[RTA_SRC]) {
80 if (r->rtm_src_len != host_len) { 79 if (r->rtm_src_len != host_len) {
81 fprintf(fp, "%s/%u", rt_addr_n2a(r->rtm_family, 80 printf("%s/%u", rt_addr_n2a(r->rtm_family,
82 RTA_PAYLOAD(tb[RTA_SRC]), 81 RTA_PAYLOAD(tb[RTA_SRC]),
83 RTA_DATA(tb[RTA_SRC]), 82 RTA_DATA(tb[RTA_SRC]),
84 abuf, sizeof(abuf)), 83 abuf, sizeof(abuf)),
@@ -88,73 +87,73 @@ static int print_rule(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
88 fputs(format_host(r->rtm_family, 87 fputs(format_host(r->rtm_family,
89 RTA_PAYLOAD(tb[RTA_SRC]), 88 RTA_PAYLOAD(tb[RTA_SRC]),
90 RTA_DATA(tb[RTA_SRC]), 89 RTA_DATA(tb[RTA_SRC]),
91 abuf, sizeof(abuf)), fp); 90 abuf, sizeof(abuf)), stdout);
92 } 91 }
93 } else if (r->rtm_src_len) { 92 } else if (r->rtm_src_len) {
94 fprintf(fp, "0/%d", r->rtm_src_len); 93 printf("0/%d", r->rtm_src_len);
95 } else { 94 } else {
96 fprintf(fp, "all"); 95 printf("all");
97 } 96 }
98 fprintf(fp, " "); 97 bb_putchar(' ');
99 98
100 if (tb[RTA_DST]) { 99 if (tb[RTA_DST]) {
101 if (r->rtm_dst_len != host_len) { 100 if (r->rtm_dst_len != host_len) {
102 fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family, 101 printf("to %s/%u ", rt_addr_n2a(r->rtm_family,
103 RTA_PAYLOAD(tb[RTA_DST]), 102 RTA_PAYLOAD(tb[RTA_DST]),
104 RTA_DATA(tb[RTA_DST]), 103 RTA_DATA(tb[RTA_DST]),
105 abuf, sizeof(abuf)), 104 abuf, sizeof(abuf)),
106 r->rtm_dst_len 105 r->rtm_dst_len
107 ); 106 );
108 } else { 107 } else {
109 fprintf(fp, "to %s ", format_host(r->rtm_family, 108 printf("to %s ", format_host(r->rtm_family,
110 RTA_PAYLOAD(tb[RTA_DST]), 109 RTA_PAYLOAD(tb[RTA_DST]),
111 RTA_DATA(tb[RTA_DST]), 110 RTA_DATA(tb[RTA_DST]),
112 abuf, sizeof(abuf))); 111 abuf, sizeof(abuf)));
113 } 112 }
114 } else if (r->rtm_dst_len) { 113 } else if (r->rtm_dst_len) {
115 fprintf(fp, "to 0/%d ", r->rtm_dst_len); 114 printf("to 0/%d ", r->rtm_dst_len);
116 } 115 }
117 116
118 if (r->rtm_tos) { 117 if (r->rtm_tos) {
119 fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1))); 118 printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
120 } 119 }
121 if (tb[RTA_PROTOINFO]) { 120 if (tb[RTA_PROTOINFO]) {
122 fprintf(fp, "fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO])); 121 printf("fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO]));
123 } 122 }
124 123
125 if (tb[RTA_IIF]) { 124 if (tb[RTA_IIF]) {
126 fprintf(fp, "iif %s ", (char*)RTA_DATA(tb[RTA_IIF])); 125 printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
127 } 126 }
128 127
129 if (r->rtm_table) 128 if (r->rtm_table)
130 fprintf(fp, "lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1, sizeof(b1))); 129 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1, sizeof(b1)));
131 130
132 if (tb[RTA_FLOW]) { 131 if (tb[RTA_FLOW]) {
133 uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]); 132 uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]);
134 uint32_t from = to>>16; 133 uint32_t from = to>>16;
135 to &= 0xFFFF; 134 to &= 0xFFFF;
136 if (from) { 135 if (from) {
137 fprintf(fp, "realms %s/", 136 printf("realms %s/",
138 rtnl_rtrealm_n2a(from, b1, sizeof(b1))); 137 rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
139 } 138 }
140 fprintf(fp, "%s ", 139 printf("%s ",
141 rtnl_rtrealm_n2a(to, b1, sizeof(b1))); 140 rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
142 } 141 }
143 142
144 if (r->rtm_type == RTN_NAT) { 143 if (r->rtm_type == RTN_NAT) {
145 if (tb[RTA_GATEWAY]) { 144 if (tb[RTA_GATEWAY]) {
146 fprintf(fp, "map-to %s ", 145 printf("map-to %s ",
147 format_host(r->rtm_family, 146 format_host(r->rtm_family,
148 RTA_PAYLOAD(tb[RTA_GATEWAY]), 147 RTA_PAYLOAD(tb[RTA_GATEWAY]),
149 RTA_DATA(tb[RTA_GATEWAY]), 148 RTA_DATA(tb[RTA_GATEWAY]),
150 abuf, sizeof(abuf))); 149 abuf, sizeof(abuf)));
151 } else 150 } else
152 fprintf(fp, "masquerade"); 151 printf("masquerade");
153 } else if (r->rtm_type != RTN_UNICAST) 152 } else if (r->rtm_type != RTN_UNICAST)
154 fputs(rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)), fp); 153 fputs(rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)), stdout);
155 154
156 fputc('\n', fp); 155 bb_putchar('\n');
157 fflush(fp); 156 /*fflush(stdout);*/
158 return 0; 157 return 0;
159} 158}
160 159
@@ -176,7 +175,7 @@ static int iprule_list(char **argv)
176 xrtnl_open(&rth); 175 xrtnl_open(&rth);
177 176
178 xrtnl_wilddump_request(&rth, af, RTM_GETRULE); 177 xrtnl_wilddump_request(&rth, af, RTM_GETRULE);
179 xrtnl_dump_filter(&rth, print_rule, stdout); 178 xrtnl_dump_filter(&rth, print_rule, NULL);
180 179
181 return 0; 180 return 0;
182} 181}