]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | #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 | ||
11 | extern int preferred_family; | |
12 | extern int show_stats; | |
13 | extern int show_details; | |
14 | extern int show_raw; | |
15 | extern int resolve_hosts; | |
16 | extern int oneline; | |
90f93024 | 17 | extern int timestamp; |
aba5acdf SH |
18 | extern 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 | |
c7699875 | 26 | #ifndef IPPROTO_COMP |
27 | #define IPPROTO_COMP 108 | |
28 | #endif | |
bd641cd6 | 29 | #ifndef IPSEC_PROTO_ANY |
30 | #define IPSEC_PROTO_ANY 255 | |
31 | #endif | |
aba5acdf SH |
32 | |
33 | #define SPRINT_BSIZE 64 | |
34 | #define SPRINT_BUF(x) char x[SPRINT_BSIZE] | |
35 | ||
36 | extern void incomplete_command(void) __attribute__((noreturn)); | |
37 | ||
38 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) | |
c7699875 | 39 | #define NEXT_ARG_OK() (argc - 1 > 0) |
40 | #define PREV_ARG() do { argv--; argc++; } while(0) | |
aba5acdf SH |
41 | |
42 | typedef struct | |
43 | { | |
44 | __u8 family; | |
45 | __u8 bytelen; | |
46 | __s16 bitlen; | |
f082b64f | 47 | __u32 flags; |
aba5acdf SH |
48 | __u32 data[4]; |
49 | } inet_prefix; | |
50 | ||
f082b64f | 51 | #define PREFIXLEN_SPECIFIED 1 |
52 | ||
aba5acdf SH |
53 | #define DN_MAXADDL 20 |
54 | #ifndef AF_DECnet | |
55 | #define AF_DECnet 12 | |
56 | #endif | |
57 | ||
58 | struct dn_naddr | |
59 | { | |
60 | unsigned short a_len; | |
61 | unsigned char a_addr[DN_MAXADDL]; | |
62 | }; | |
63 | ||
64 | #define IPX_NODE_LEN 6 | |
65 | ||
66 | struct ipx_addr { | |
67 | u_int32_t ipx_net; | |
68 | u_int8_t ipx_node[IPX_NODE_LEN]; | |
69 | }; | |
70 | ||
c7699875 | 71 | extern __u32 get_addr32(const char *name); |
04457b3d | 72 | extern int get_addr_1(inet_prefix *dst, const char *arg, int family); |
fb9b1d0f | 73 | extern int get_prefix_1(inet_prefix *dst, char *arg, int family); |
c7699875 | 74 | extern int get_addr(inet_prefix *dst, const char *arg, int family); |
fb9b1d0f | 75 | extern int get_prefix(inet_prefix *dst, char *arg, int family); |
aba5acdf | 76 | |
04457b3d SH |
77 | extern int get_integer(int *val, const char *arg, int base); |
78 | extern int get_unsigned(unsigned *val, const char *arg, int base); | |
aba5acdf SH |
79 | #define get_byte get_u8 |
80 | #define get_ushort get_u16 | |
81 | #define get_short get_s16 | |
c7699875 | 82 | extern int get_u64(__u64 *val, const char *arg, int base); |
04457b3d SH |
83 | extern int get_u32(__u32 *val, const char *arg, int base); |
84 | extern int get_u16(__u16 *val, const char *arg, int base); | |
85 | extern int get_s16(__s16 *val, const char *arg, int base); | |
86 | extern int get_u8(__u8 *val, const char *arg, int base); | |
87 | extern int get_s8(__s8 *val, const char *arg, int base); | |
aba5acdf | 88 | |
f332d169 SH |
89 | extern char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen); |
90 | extern __u8* hexstring_a2n(const char *str, __u8 *buf, int blen); | |
aba5acdf | 91 | |
04457b3d SH |
92 | extern const char *format_host(int af, int len, const void *addr, |
93 | char *buf, int buflen); | |
94 | extern const char *rt_addr_n2a(int af, int len, const void *addr, | |
95 | char *buf, int buflen); | |
aba5acdf | 96 | |
c7699875 | 97 | void missarg(const char *) __attribute__((noreturn)); |
04457b3d SH |
98 | void invarg(const char *, const char *) __attribute__((noreturn)); |
99 | void duparg(const char *, const char *) __attribute__((noreturn)); | |
100 | void duparg2(const char *, const char *) __attribute__((noreturn)); | |
101 | int matches(const char *arg, const char *pattern); | |
102 | extern int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); | |
aba5acdf SH |
103 | |
104 | const char *dnet_ntop(int af, const void *addr, char *str, size_t len); | |
105 | int dnet_pton(int af, const char *src, void *addr); | |
106 | ||
107 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len); | |
108 | int ipx_pton(int af, const char *src, void *addr); | |
109 | ||
110 | extern int __iproute2_hz_internal; | |
111 | extern int __get_hz(void); | |
112 | ||
113 | static __inline__ int get_hz(void) | |
114 | { | |
115 | if (__iproute2_hz_internal == 0) | |
116 | __iproute2_hz_internal = __get_hz(); | |
117 | return __iproute2_hz_internal; | |
118 | } | |
119 | ||
5e8bc631 | 120 | extern int __iproute2_user_hz_internal; |
121 | extern int __get_user_hz(void); | |
122 | ||
123 | static __inline__ int get_user_hz(void) | |
124 | { | |
125 | if (__iproute2_user_hz_internal == 0) | |
126 | __iproute2_user_hz_internal = __get_user_hz(); | |
127 | return __iproute2_user_hz_internal; | |
128 | } | |
129 | ||
90f93024 SH |
130 | int print_timestamp(FILE *fp); |
131 | ||
02d2ae55 SH |
132 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
133 | ||
351efcde SH |
134 | extern int cmdlineno; |
135 | extern size_t getcmdline(char **line, size_t *len, FILE *in); | |
136 | extern int makeargs(char *line, char *argv[], int maxargs); | |
137 | ||
aba5acdf | 138 | #endif /* __UTILS_H__ */ |