"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 2 | #ifndef __UTILS_H__ |
| 3 | #define __UTILS_H__ 1 |
| 4 | |
Bernhard Reutner-Fischer | 19008b8 | 2006-06-07 20:17:41 +0000 | [diff] [blame] | 5 | #include "libbb.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 6 | #include <asm/types.h> |
| 7 | #include <resolv.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 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 | |
| 28 | #define SPRINT_BSIZE 64 |
| 29 | #define SPRINT_BUF(x) char x[SPRINT_BSIZE] |
| 30 | |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 31 | extern void incomplete_command(void) ATTRIBUTE_NORETURN; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 32 | |
| 33 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) |
| 34 | |
| 35 | typedef struct |
| 36 | { |
| 37 | __u8 family; |
| 38 | __u8 bytelen; |
| 39 | __s16 bitlen; |
| 40 | __u32 data[4]; |
| 41 | } inet_prefix; |
| 42 | |
| 43 | #define DN_MAXADDL 20 |
| 44 | #ifndef AF_DECnet |
| 45 | #define AF_DECnet 12 |
| 46 | #endif |
| 47 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 48 | struct dn_naddr |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 49 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 50 | unsigned short a_len; |
| 51 | unsigned char a_addr[DN_MAXADDL]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | #define IPX_NODE_LEN 6 |
| 55 | |
| 56 | struct ipx_addr { |
Eric Andersen | 1a834be | 2004-01-30 22:59:50 +0000 | [diff] [blame] | 57 | uint32_t ipx_net; |
| 58 | uint8_t ipx_node[IPX_NODE_LEN]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | extern __u32 get_addr32(char *name); |
| 62 | extern int get_addr_1(inet_prefix *dst, char *arg, int family); |
| 63 | extern int get_prefix_1(inet_prefix *dst, char *arg, int family); |
| 64 | extern int get_addr(inet_prefix *dst, char *arg, int family); |
| 65 | extern int get_prefix(inet_prefix *dst, char *arg, int family); |
| 66 | |
| 67 | extern int get_integer(int *val, char *arg, int base); |
| 68 | extern int get_unsigned(unsigned *val, char *arg, int base); |
| 69 | #define get_byte get_u8 |
| 70 | #define get_ushort get_u16 |
| 71 | #define get_short get_s16 |
| 72 | extern int get_u32(__u32 *val, char *arg, int base); |
| 73 | extern int get_u16(__u16 *val, char *arg, int base); |
| 74 | extern int get_s16(__s16 *val, char *arg, int base); |
| 75 | extern int get_u8(__u8 *val, char *arg, int base); |
| 76 | extern int get_s8(__s8 *val, char *arg, int base); |
| 77 | |
| 78 | extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); |
| 79 | extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen); |
| 80 | |
Bernhard Reutner-Fischer | f1bd42a | 2006-06-14 16:51:50 +0000 | [diff] [blame] | 81 | void invarg(const char * const, const char * const) ATTRIBUTE_NORETURN; |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 82 | void duparg(char *, char *) ATTRIBUTE_NORETURN; |
| 83 | void duparg2(char *, char *) ATTRIBUTE_NORETURN; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 84 | int matches(char *arg, char *pattern); |
| 85 | extern int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits); |
| 86 | |
| 87 | const char *dnet_ntop(int af, const void *addr, char *str, size_t len); |
| 88 | int dnet_pton(int af, const char *src, void *addr); |
| 89 | |
| 90 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len); |
| 91 | int ipx_pton(int af, const char *src, void *addr); |
| 92 | |
| 93 | extern int __iproute2_hz_internal; |
| 94 | extern int __get_hz(void); |
| 95 | |
| 96 | static __inline__ int get_hz(void) |
| 97 | { |
| 98 | if (__iproute2_hz_internal == 0) |
| 99 | __iproute2_hz_internal = __get_hz(); |
| 100 | return __iproute2_hz_internal; |
| 101 | } |
| 102 | |
| 103 | #endif /* __UTILS_H__ */ |