"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 2 | #ifndef UTILS_H |
| 3 | #define UTILS_H 1 |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 4 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 5 | #include "libnetlink.h" |
| 6 | #include "ll_map.h" |
| 7 | #include "rtm_map.h" |
| 8 | |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 9 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
Denis Vlasenko | 98636eb | 2008-05-09 17:59:34 +0000 | [diff] [blame] | 10 | |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 11 | extern family_t preferred_family; |
Denis Vlasenko | 540a2a1 | 2007-04-07 01:14:45 +0000 | [diff] [blame] | 12 | extern smallint show_stats; /* UNUSED */ |
| 13 | extern smallint show_details; /* UNUSED */ |
| 14 | extern smallint show_raw; /* UNUSED */ |
| 15 | extern smallint resolve_hosts; /* UNUSED */ |
| 16 | extern smallint oneline; |
| 17 | extern char _SL_; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 18 | |
| 19 | #ifndef IPPROTO_ESP |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 20 | #define IPPROTO_ESP 50 |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 21 | #endif |
| 22 | #ifndef IPPROTO_AH |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 23 | #define IPPROTO_AH 51 |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | #define SPRINT_BSIZE 64 |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 27 | #define SPRINT_BUF(x) char x[SPRINT_BSIZE] |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | 3e57adb | 2008-05-31 07:33:18 +0000 | [diff] [blame] | 29 | typedef struct { |
Denis Vlasenko | 98ee06d | 2006-12-31 18:57:37 +0000 | [diff] [blame] | 30 | uint8_t family; |
| 31 | uint8_t bytelen; |
| 32 | int16_t bitlen; |
| 33 | uint32_t data[4]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 34 | } inet_prefix; |
| 35 | |
Bernhard Reutner-Fischer | 8fbd8ac | 2008-10-21 12:42:45 +0000 | [diff] [blame] | 36 | #define PREFIXLEN_SPECIFIED 1 |
| 37 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 38 | #define DN_MAXADDL 20 |
| 39 | #ifndef AF_DECnet |
| 40 | #define AF_DECnet 12 |
| 41 | #endif |
| 42 | |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 43 | struct dn_naddr { |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 44 | unsigned short a_len; |
| 45 | unsigned char a_addr[DN_MAXADDL]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | #define IPX_NODE_LEN 6 |
| 49 | |
| 50 | struct ipx_addr { |
Eric Andersen | 1a834be | 2004-01-30 22:59:50 +0000 | [diff] [blame] | 51 | uint32_t ipx_net; |
| 52 | uint8_t ipx_node[IPX_NODE_LEN]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 55 | char** next_arg(char **argv) FAST_FUNC; |
| 56 | #define NEXT_ARG() do { argv = next_arg(argv); } while (0) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 57 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 58 | uint32_t get_addr32(char *name) FAST_FUNC; |
| 59 | int get_addr_1(inet_prefix *dst, char *arg, int family) FAST_FUNC; |
| 60 | /*void get_prefix_1(inet_prefix *dst, char *arg, int family) FAST_FUNC;*/ |
| 61 | int get_addr(inet_prefix *dst, char *arg, int family) FAST_FUNC; |
| 62 | void get_prefix(inet_prefix *dst, char *arg, int family) FAST_FUNC; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 63 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 64 | unsigned get_unsigned(char *arg, const char *errmsg) FAST_FUNC; |
| 65 | uint32_t get_u32(char *arg, const char *errmsg) FAST_FUNC; |
| 66 | uint16_t get_u16(char *arg, const char *errmsg) FAST_FUNC; |
| 67 | |
| 68 | const char *rt_addr_n2a(int af, void *addr) FAST_FUNC; |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 69 | #ifdef RESOLVE_HOSTNAMES |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 70 | const char *format_host(int af, int len, void *addr) FAST_FUNC; |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 71 | #else |
Denys Vlasenko | 926d801 | 2015-10-14 13:56:42 +0200 | [diff] [blame] | 72 | #define format_host(af, len, addr) \ |
| 73 | rt_addr_n2a(af, addr) |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 74 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 75 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 76 | void invarg_1_to_2(const char *, const char *) FAST_FUNC NORETURN; |
| 77 | void duparg(const char *, const char *) FAST_FUNC NORETURN; |
| 78 | void duparg2(const char *, const char *) FAST_FUNC NORETURN; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 79 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 80 | int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) FAST_FUNC; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 81 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 82 | //const char *dnet_ntop(int af, const void *addr, char *str, size_t len); |
| 83 | //int dnet_pton(int af, const char *src, void *addr); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 84 | |
Denys Vlasenko | 826bdcd | 2017-04-07 17:15:40 +0200 | [diff] [blame] | 85 | //const char *ipx_ntop(int af, const void *addr, char *str, size_t len); |
| 86 | //int ipx_pton(int af, const char *src, void *addr); |
| 87 | |
| 88 | unsigned get_hz(void) FAST_FUNC; |
Curt Brune | 6993470 | 2015-10-14 12:53:47 +0200 | [diff] [blame] | 89 | |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 90 | POP_SAVED_FUNCTION_VISIBILITY |
Denis Vlasenko | 98636eb | 2008-05-09 17:59:34 +0000 | [diff] [blame] | 91 | |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 92 | #endif |