blob: e79e177b9e0e58523ffc5842d945b4b8c2f0cc82 [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"
10
11extern int preferred_family;
12extern int show_stats;
13extern int show_details;
14extern int show_raw;
15extern int resolve_hosts;
16extern int oneline;
17extern char * _SL_;
18
19#ifndef IPPROTO_ESP
20#define IPPROTO_ESP 50
21#endif
22#ifndef IPPROTO_AH
23#define IPPROTO_AH 51
24#endif
25
26#define SPRINT_BSIZE 64
27#define SPRINT_BUF(x) char x[SPRINT_BSIZE]
28
29extern void incomplete_command(void) __attribute__((noreturn));
30
31#define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
32
33typedef struct
34{
35 __u8 family;
36 __u8 bytelen;
37 __s16 bitlen;
38 __u32 data[4];
39} inet_prefix;
40
41#define DN_MAXADDL 20
42#ifndef AF_DECnet
43#define AF_DECnet 12
44#endif
45
Eric Andersenc7bda1c2004-03-15 08:29:22 +000046struct dn_naddr
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000047{
48 unsigned short a_len;
49 unsigned char a_addr[DN_MAXADDL];
50};
51
52#define IPX_NODE_LEN 6
53
54struct ipx_addr {
Eric Andersen1a834be2004-01-30 22:59:50 +000055 uint32_t ipx_net;
56 uint8_t ipx_node[IPX_NODE_LEN];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000057};
58
59extern __u32 get_addr32(char *name);
60extern int get_addr_1(inet_prefix *dst, char *arg, int family);
61extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
62extern int get_addr(inet_prefix *dst, char *arg, int family);
63extern int get_prefix(inet_prefix *dst, char *arg, int family);
64
65extern int get_integer(int *val, char *arg, int base);
66extern int get_unsigned(unsigned *val, char *arg, int base);
67#define get_byte get_u8
68#define get_ushort get_u16
69#define get_short get_s16
70extern int get_u32(__u32 *val, char *arg, int base);
71extern int get_u16(__u16 *val, char *arg, int base);
72extern int get_s16(__s16 *val, char *arg, int base);
73extern int get_u8(__u8 *val, char *arg, int base);
74extern int get_s8(__s8 *val, char *arg, int base);
75
76extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
77extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen);
78
79void invarg(char *, char *) __attribute__((noreturn));
80void duparg(char *, char *) __attribute__((noreturn));
81void duparg2(char *, char *) __attribute__((noreturn));
82int matches(char *arg, char *pattern);
83extern int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
84
85const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
86int dnet_pton(int af, const char *src, void *addr);
87
88const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
89int ipx_pton(int af, const char *src, void *addr);
90
91extern int __iproute2_hz_internal;
92extern int __get_hz(void);
93
94static __inline__ int get_hz(void)
95{
96 if (__iproute2_hz_internal == 0)
97 __iproute2_hz_internal = __get_hz();
98 return __iproute2_hz_internal;
99}
100
101#endif /* __UTILS_H__ */