blob: 0a3a06c150506ee0c225e2eed3e6e59d2a8b4fdd [file] [log] [blame]
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00001#ifndef __UTILS_H__
2#define __UTILS_H__ 1
3
4#include <asm/types.h>
5#include <resolv.h>
6
7#include "libnetlink.h"
8#include "ll_map.h"
9#include "rtm_map.h"
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000010#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000011
12extern int preferred_family;
13extern int show_stats;
14extern int show_details;
15extern int show_raw;
16extern int resolve_hosts;
17extern int oneline;
18extern char * _SL_;
19
20#ifndef IPPROTO_ESP
21#define IPPROTO_ESP 50
22#endif
23#ifndef IPPROTO_AH
24#define IPPROTO_AH 51
25#endif
26
27#define SPRINT_BSIZE 64
28#define SPRINT_BUF(x) char x[SPRINT_BSIZE]
29
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000030extern void incomplete_command(void) ATTRIBUTE_NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000031
32#define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
33
34typedef struct
35{
36 __u8 family;
37 __u8 bytelen;
38 __s16 bitlen;
39 __u32 data[4];
40} inet_prefix;
41
42#define DN_MAXADDL 20
43#ifndef AF_DECnet
44#define AF_DECnet 12
45#endif
46
Eric Andersenc7bda1c2004-03-15 08:29:22 +000047struct dn_naddr
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000048{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000049 unsigned short a_len;
50 unsigned char a_addr[DN_MAXADDL];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000051};
52
53#define IPX_NODE_LEN 6
54
55struct ipx_addr {
Eric Andersen1a834be2004-01-30 22:59:50 +000056 uint32_t ipx_net;
57 uint8_t ipx_node[IPX_NODE_LEN];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000058};
59
60extern __u32 get_addr32(char *name);
61extern int get_addr_1(inet_prefix *dst, char *arg, int family);
62extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
63extern int get_addr(inet_prefix *dst, char *arg, int family);
64extern int get_prefix(inet_prefix *dst, char *arg, int family);
65
66extern int get_integer(int *val, char *arg, int base);
67extern int get_unsigned(unsigned *val, char *arg, int base);
68#define get_byte get_u8
69#define get_ushort get_u16
70#define get_short get_s16
71extern int get_u32(__u32 *val, char *arg, int base);
72extern int get_u16(__u16 *val, char *arg, int base);
73extern int get_s16(__s16 *val, char *arg, int base);
74extern int get_u8(__u8 *val, char *arg, int base);
75extern int get_s8(__s8 *val, char *arg, int base);
76
77extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
78extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen);
79
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000080void invarg(char *, char *) ATTRIBUTE_NORETURN;
81void duparg(char *, char *) ATTRIBUTE_NORETURN;
82void duparg2(char *, char *) ATTRIBUTE_NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000083int matches(char *arg, char *pattern);
84extern int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
85
86const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
87int dnet_pton(int af, const char *src, void *addr);
88
89const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
90int ipx_pton(int af, const char *src, void *addr);
91
92extern int __iproute2_hz_internal;
93extern int __get_hz(void);
94
95static __inline__ int get_hz(void)
96{
97 if (__iproute2_hz_internal == 0)
98 __iproute2_hz_internal = __get_hz();
99 return __iproute2_hz_internal;
100}
101
102#endif /* __UTILS_H__ */