aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/utils.c')
-rw-r--r--networking/libiproute/utils.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
index d0fe30605..42025bc66 100644
--- a/networking/libiproute/utils.c
+++ b/networking/libiproute/utils.c
@@ -13,6 +13,28 @@
13#include "utils.h" 13#include "utils.h"
14#include "inet_common.h" 14#include "inet_common.h"
15 15
16unsigned get_hz(void)
17{
18 static unsigned hz_internal;
19 FILE *fp;
20
21 if (hz_internal)
22 return hz_internal;
23
24 fp = fopen_for_read("/proc/net/psched");
25 if (fp) {
26 unsigned nom, denom;
27
28 if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)
29 if (nom == 1000000)
30 hz_internal = denom;
31 fclose(fp);
32 }
33 if (!hz_internal)
34 hz_internal = bb_clk_tck();
35 return hz_internal;
36}
37
16unsigned get_unsigned(char *arg, const char *errmsg) 38unsigned get_unsigned(char *arg, const char *errmsg)
17{ 39{
18 unsigned long res; 40 unsigned long res;
@@ -25,7 +47,7 @@ unsigned get_unsigned(char *arg, const char *errmsg)
25 return res; 47 return res;
26 } 48 }
27 } 49 }
28 invarg(arg, errmsg); /* does not return */ 50 invarg_1_to_2(arg, errmsg); /* does not return */
29} 51}
30 52
31uint32_t get_u32(char *arg, const char *errmsg) 53uint32_t get_u32(char *arg, const char *errmsg)
@@ -40,7 +62,7 @@ uint32_t get_u32(char *arg, const char *errmsg)
40 return res; 62 return res;
41 } 63 }
42 } 64 }
43 invarg(arg, errmsg); /* does not return */ 65 invarg_1_to_2(arg, errmsg); /* does not return */
44} 66}
45 67
46uint16_t get_u16(char *arg, const char *errmsg) 68uint16_t get_u16(char *arg, const char *errmsg)
@@ -55,7 +77,7 @@ uint16_t get_u16(char *arg, const char *errmsg)
55 return res; 77 return res;
56 } 78 }
57 } 79 }
58 invarg(arg, errmsg); /* does not return */ 80 invarg_1_to_2(arg, errmsg); /* does not return */
59} 81}
60 82
61int get_addr_1(inet_prefix *addr, char *name, int family) 83int get_addr_1(inet_prefix *addr, char *name, int family)
@@ -208,12 +230,12 @@ uint32_t get_addr32(char *name)
208 230
209void incomplete_command(void) 231void incomplete_command(void)
210{ 232{
211 bb_error_msg_and_die("command line is not complete, try option \"help\""); 233 bb_error_msg_and_die("command line is not complete, try \"help\"");
212} 234}
213 235
214void invarg(const char *arg, const char *opt) 236void invarg_1_to_2(const char *arg, const char *opt)
215{ 237{
216 bb_error_msg_and_die(bb_msg_invalid_arg, arg, opt); 238 bb_error_msg_and_die(bb_msg_invalid_arg_to, arg, opt);
217} 239}
218 240
219void duparg(const char *key, const char *arg) 241void duparg(const char *key, const char *arg)
@@ -254,20 +276,21 @@ int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)
254 return 0; 276 return 0;
255} 277}
256 278
257const char *rt_addr_n2a(int af, 279const char *rt_addr_n2a(int af, void *addr)
258 void *addr, char *buf, int buflen)
259{ 280{
260 switch (af) { 281 switch (af) {
261 case AF_INET: 282 case AF_INET:
262 case AF_INET6: 283 case AF_INET6:
263 return inet_ntop(af, addr, buf, buflen); 284 return inet_ntop(af, addr,
285 auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN
286 );
264 default: 287 default:
265 return "???"; 288 return "???";
266 } 289 }
267} 290}
268 291
269#ifdef RESOLVE_HOSTNAMES 292#ifdef RESOLVE_HOSTNAMES
270const char *format_host(int af, int len, void *addr, char *buf, int buflen) 293const char *format_host(int af, int len, void *addr)
271{ 294{
272 if (resolve_hosts) { 295 if (resolve_hosts) {
273 struct hostent *h_ent; 296 struct hostent *h_ent;
@@ -286,11 +309,10 @@ const char *format_host(int af, int len, void *addr, char *buf, int buflen)
286 if (len > 0) { 309 if (len > 0) {
287 h_ent = gethostbyaddr(addr, len, af); 310 h_ent = gethostbyaddr(addr, len, af);
288 if (h_ent != NULL) { 311 if (h_ent != NULL) {
289 safe_strncpy(buf, h_ent->h_name, buflen); 312 return auto_string(xstrdup(h_ent->h_name));
290 return buf;
291 } 313 }
292 } 314 }
293 } 315 }
294 return rt_addr_n2a(af, addr, buf, buflen); 316 return rt_addr_n2a(af, addr);
295} 317}
296#endif 318#endif