aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/iprule.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-05 05:00:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-05 05:00:24 +0000
commitbedfabd500b5dd684ac0b0780147a81bbb37f084 (patch)
treeb7fdfb53a93ef06cf586512ab9f0ae4853b18a11 /networking/libiproute/iprule.c
parentb6fe10091d1fb1fd661a464c4b5ab6a457614b44 (diff)
downloadbusybox-w32-bedfabd500b5dd684ac0b0780147a81bbb37f084.tar.gz
busybox-w32-bedfabd500b5dd684ac0b0780147a81bbb37f084.tar.bz2
busybox-w32-bedfabd500b5dd684ac0b0780147a81bbb37f084.zip
libiproute: use stdout directly instead of passing it as a parameter
function old new delta iprule_list 86 82 -4 print_rule 860 791 -69 ipaddr_list_or_flush 2484 2384 -100 print_addrinfo 1498 1292 -206 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-379) Total: -379 bytes
Diffstat (limited to 'networking/libiproute/iprule.c')
-rw-r--r--networking/libiproute/iprule.c49
1 files changed, 24 insertions, 25 deletions
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}