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