]> git.proxmox.com Git - mirror_iproute2.git/blob - include/utils.h
Import patch ipxfrm-20040707_2.diff
[mirror_iproute2.git] / include / utils.h
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;
17 extern 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 #ifndef IPPROTO_COMP
26 #define IPPROTO_COMP 108
27 #endif
28
29 #define SPRINT_BSIZE 64
30 #define SPRINT_BUF(x) char x[SPRINT_BSIZE]
31
32 extern void incomplete_command(void) __attribute__((noreturn));
33
34 #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
35 #define NEXT_ARG_OK() (argc - 1 > 0)
36 #define PREV_ARG() do { argv--; argc++; } while(0)
37
38 typedef struct
39 {
40 __u8 family;
41 __u8 bytelen;
42 __s16 bitlen;
43 __u32 data[4];
44 } inet_prefix;
45
46 #define DN_MAXADDL 20
47 #ifndef AF_DECnet
48 #define AF_DECnet 12
49 #endif
50
51 struct dn_naddr
52 {
53 unsigned short a_len;
54 unsigned char a_addr[DN_MAXADDL];
55 };
56
57 #define IPX_NODE_LEN 6
58
59 struct ipx_addr {
60 u_int32_t ipx_net;
61 u_int8_t ipx_node[IPX_NODE_LEN];
62 };
63
64 extern __u32 get_addr32(const char *name);
65 extern int get_addr_1(inet_prefix *dst, const char *arg, int family);
66 extern int get_prefix_1(inet_prefix *dst, const char *arg, int family);
67 extern int get_addr(inet_prefix *dst, const char *arg, int family);
68 extern int get_prefix(inet_prefix *dst, const char *arg, int family);
69
70 extern int get_integer(int *val, const char *arg, int base);
71 extern int get_unsigned(unsigned *val, const char *arg, int base);
72 #define get_byte get_u8
73 #define get_ushort get_u16
74 #define get_short get_s16
75 extern int get_u64(__u64 *val, const char *arg, int base);
76 extern int get_u32(__u32 *val, const char *arg, int base);
77 extern int get_u16(__u16 *val, const char *arg, int base);
78 extern int get_s16(__s16 *val, const char *arg, int base);
79 extern int get_u8(__u8 *val, const char *arg, int base);
80 extern int get_s8(__s8 *val, const char *arg, int base);
81
82 extern __u8* hexstring_n2a(const __u8 *str, int len, __u8 *buf, int blen);
83 extern __u8* hexstring_a2n(const __u8 *str, __u8 *buf, int blen);
84
85 extern const char *format_host(int af, int len, const void *addr,
86 char *buf, int buflen);
87 extern const char *rt_addr_n2a(int af, int len, const void *addr,
88 char *buf, int buflen);
89
90 void missarg(const char *) __attribute__((noreturn));
91 void invarg(const char *, const char *) __attribute__((noreturn));
92 void duparg(const char *, const char *) __attribute__((noreturn));
93 void duparg2(const char *, const char *) __attribute__((noreturn));
94 int matches(const char *arg, const char *pattern);
95 extern int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
96
97 const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
98 int dnet_pton(int af, const char *src, void *addr);
99
100 const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
101 int ipx_pton(int af, const char *src, void *addr);
102
103 extern int __iproute2_hz_internal;
104 extern int __get_hz(void);
105
106 static __inline__ int get_hz(void)
107 {
108 if (__iproute2_hz_internal == 0)
109 __iproute2_hz_internal = __get_hz();
110 return __iproute2_hz_internal;
111 }
112
113 #endif /* __UTILS_H__ */