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