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