]> git.proxmox.com Git - mirror_iproute2.git/blob - include/utils.h
cleanup warnings
[mirror_iproute2.git] / include / utils.h
1 #ifndef __UTILS_H__
2 #define __UTILS_H__ 1
3
4 #include <sys/types.h>
5 #include <asm/types.h>
6 #include <resolv.h>
7 #include <stdlib.h>
8
9 #include "libnetlink.h"
10 #include "ll_map.h"
11 #include "rtm_map.h"
12
13 extern int preferred_family;
14 extern int show_stats;
15 extern int show_details;
16 extern int show_raw;
17 extern int resolve_hosts;
18 extern int oneline;
19 extern int timestamp;
20 extern char * _SL_;
21 extern int max_flush_loops;
22 extern int batch_mode;
23
24 #ifndef IPPROTO_ESP
25 #define IPPROTO_ESP 50
26 #endif
27 #ifndef IPPROTO_AH
28 #define IPPROTO_AH 51
29 #endif
30 #ifndef IPPROTO_COMP
31 #define IPPROTO_COMP 108
32 #endif
33 #ifndef IPSEC_PROTO_ANY
34 #define IPSEC_PROTO_ANY 255
35 #endif
36
37 #define SPRINT_BSIZE 64
38 #define SPRINT_BUF(x) char x[SPRINT_BSIZE]
39
40 extern void incomplete_command(void) __attribute__((noreturn));
41
42 #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
43 #define NEXT_ARG_OK() (argc - 1 > 0)
44 #define PREV_ARG() do { argv--; argc++; } while(0)
45
46 typedef struct
47 {
48 __u8 family;
49 __u8 bytelen;
50 __s16 bitlen;
51 __u32 flags;
52 __u32 data[8];
53 } inet_prefix;
54
55 #define PREFIXLEN_SPECIFIED 1
56
57 #define DN_MAXADDL 20
58 #ifndef AF_DECnet
59 #define AF_DECnet 12
60 #endif
61
62 struct dn_naddr
63 {
64 unsigned short a_len;
65 unsigned char a_addr[DN_MAXADDL];
66 };
67
68 #define IPX_NODE_LEN 6
69
70 struct ipx_addr {
71 u_int32_t ipx_net;
72 u_int8_t ipx_node[IPX_NODE_LEN];
73 };
74
75 extern __u32 get_addr32(const char *name);
76 extern int get_addr_1(inet_prefix *dst, const char *arg, int family);
77 extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
78 extern int get_addr(inet_prefix *dst, const char *arg, int family);
79 extern int get_prefix(inet_prefix *dst, char *arg, int family);
80 extern int mask2bits(__u32 netmask);
81
82 extern int get_integer(int *val, const char *arg, int base);
83 extern int get_unsigned(unsigned *val, const char *arg, int base);
84 extern int get_time_rtt(unsigned *val, const char *arg, int *raw);
85 #define get_byte get_u8
86 #define get_ushort get_u16
87 #define get_short get_s16
88 extern int get_u64(__u64 *val, const char *arg, int base);
89 extern int get_u32(__u32 *val, const char *arg, int base);
90 extern int get_s32(__s32 *val, const char *arg, int base);
91 extern int get_u16(__u16 *val, const char *arg, int base);
92 extern int get_s16(__s16 *val, const char *arg, int base);
93 extern int get_u8(__u8 *val, const char *arg, int base);
94 extern int get_s8(__s8 *val, const char *arg, int base);
95
96 extern char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
97 extern __u8* hexstring_a2n(const char *str, __u8 *buf, int blen);
98
99 extern const char *format_host(int af, int len, const void *addr,
100 char *buf, int buflen);
101 extern const char *rt_addr_n2a(int af, const void *addr,
102 char *buf, int buflen);
103
104 void missarg(const char *) __attribute__((noreturn));
105 void invarg(const char *, const char *) __attribute__((noreturn));
106 void duparg(const char *, const char *) __attribute__((noreturn));
107 void duparg2(const char *, const char *) __attribute__((noreturn));
108 int matches(const char *arg, const char *pattern);
109 extern int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
110
111 const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
112 int dnet_pton(int af, const char *src, void *addr);
113
114 const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
115 int ipx_pton(int af, const char *src, void *addr);
116
117 extern int __iproute2_hz_internal;
118 extern int __get_hz(void);
119
120 static __inline__ int get_hz(void)
121 {
122 if (__iproute2_hz_internal == 0)
123 __iproute2_hz_internal = __get_hz();
124 return __iproute2_hz_internal;
125 }
126
127 extern int __iproute2_user_hz_internal;
128 extern int __get_user_hz(void);
129
130 static __inline__ int get_user_hz(void)
131 {
132 if (__iproute2_user_hz_internal == 0)
133 __iproute2_user_hz_internal = __get_user_hz();
134 return __iproute2_user_hz_internal;
135 }
136
137 static inline __u32 nl_mgrp(__u32 group)
138 {
139 if (group > 31 ) {
140 fprintf(stderr, "Use setsockopt for this group %d\n", group);
141 exit(-1);
142 }
143 return group ? (1 << (group - 1)) : 0;
144 }
145
146
147 int print_timestamp(FILE *fp);
148
149 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
150
151 extern int cmdlineno;
152 extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
153 extern int makeargs(char *line, char *argv[], int maxargs);
154 extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6);
155
156 struct iplink_req;
157 int iplink_parse(int argc, char **argv, struct iplink_req *req,
158 char **name, char **type, char **link, char **dev,
159 int *group, int *index);
160 #endif /* __UTILS_H__ */