Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.h
Go to the documentation of this file.
1 #ifndef __UTILS_H__
2 #define __UTILS_H__ 1
3 
4 #ifndef _GNU_SOURCE
5 # define _GNU_SOURCE 1
6 #endif
7 
8 #include <asm/types.h>
9 //#include <resolv.h>
10 #include <linux/types.h>
11 #include <sys/types.h>
12 
13 #include "libnetlink.h"
14 #include "ll_map.h"
15 #include "rtm_map.h"
16 
17 extern int preferred_family;
18 extern int show_stats;
19 extern int show_details;
20 extern int show_raw;
21 extern int resolve_hosts;
22 extern int oneline;
23 extern int timestamp;
24 extern char * _SL_;
25 
26 #ifndef IPPROTO_ESP
27 #define IPPROTO_ESP 50
28 #endif
29 #ifndef IPPROTO_AH
30 #define IPPROTO_AH 51
31 #endif
32 #ifndef IPPROTO_COMP
33 #define IPPROTO_COMP 108
34 #endif
35 #ifndef IPSEC_PROTO_ANY
36 #define IPSEC_PROTO_ANY 255
37 #endif
38 
39 #define SPRINT_BSIZE 64
40 #define SPRINT_BUF(x) char x[SPRINT_BSIZE]
41 
42 extern void incomplete_command(void) __attribute__((noreturn));
43 
44 #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
45 #define NEXT_ARG_OK() (argc - 1 > 0)
46 #define PREV_ARG() do { argv--; argc++; } while(0)
47 
48 typedef struct
49 {
50  __u8 family;
51  __u8 bytelen;
52  __s16 bitlen;
53  __u32 flags;
54  __u32 data[4];
55 } inet_prefix;
56 
57 #define PREFIXLEN_SPECIFIED 1
58 
59 #define DN_MAXADDL 20
60 #ifndef AF_DECnet
61 #define AF_DECnet 12
62 #endif
63 
64 struct dn_naddr
65 {
66  unsigned short a_len;
67  unsigned char a_addr[DN_MAXADDL];
68 };
69 
70 #define IPX_NODE_LEN 6
71 
72 struct ipx_addr {
73  u_int32_t ipx_net;
75 };
76 
77 extern __u32 get_addr32(const char *name);
78 extern int get_addr_1(inet_prefix *dst, const char *arg, int family);
79 extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
80 extern int get_addr(inet_prefix *dst, const char *arg, int family);
81 extern int get_prefix(inet_prefix *dst, char *arg, int family);
82 
83 extern int get_integer(int *val, const char *arg, int base);
84 extern int get_unsigned(unsigned *val, const char *arg, int base);
85 #define get_byte get_u8
86 #define get_ushort get_u16
87 #define get_short get_s16
88 extern int get_u32(__u32 *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 
117 static __inline__ int get_hz(void)
118 {
119  return 1000;
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  return 1000;
128 }
129 
130 int print_timestamp(FILE *fp);
131 
132 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
133 
134 extern int cmdlineno;
135 extern size_t getcmdline(char **line, size_t *len, FILE *in);
136 extern int makeargs(char *line, char *argv[], int maxargs);
137 
138 #endif /* __UTILS_H__ */
139