"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 | |
| 7 | #include "libnetlink.h" |
| 8 | #include "ll_map.h" |
| 9 | #include "rtm_map.h" |
| 10 | |
| 11 | extern int preferred_family; |
| 12 | extern int show_stats; |
| 13 | extern int show_details; |
| 14 | extern int show_raw; |
| 15 | extern int resolve_hosts; |
| 16 | extern int oneline; |
| 17 | extern char * _SL_; |
| 18 | |
| 19 | #ifndef IPPROTO_ESP |
| 20 | #define IPPROTO_ESP 50 |
| 21 | #endif |
| 22 | #ifndef IPPROTO_AH |
| 23 | #define IPPROTO_AH 51 |
| 24 | #endif |
| 25 | |
| 26 | #define SPRINT_BSIZE 64 |
| 27 | #define SPRINT_BUF(x) char x[SPRINT_BSIZE] |
| 28 | |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 29 | extern void incomplete_command(void) ATTRIBUTE_NORETURN; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 30 | |
Denis Vlasenko | bf0a201 | 2006-12-26 10:42:51 +0000 | [diff] [blame] | 31 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while (0) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 32 | |
| 33 | typedef struct |
| 34 | { |
Denis Vlasenko | 98ee06d | 2006-12-31 18:57:37 +0000 | [diff] [blame] | 35 | uint8_t family; |
| 36 | uint8_t bytelen; |
| 37 | int16_t bitlen; |
| 38 | uint32_t data[4]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 39 | } inet_prefix; |
| 40 | |
| 41 | #define DN_MAXADDL 20 |
| 42 | #ifndef AF_DECnet |
| 43 | #define AF_DECnet 12 |
| 44 | #endif |
| 45 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 46 | struct dn_naddr |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 47 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 48 | unsigned short a_len; |
| 49 | unsigned char a_addr[DN_MAXADDL]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | #define IPX_NODE_LEN 6 |
| 53 | |
| 54 | struct ipx_addr { |
Eric Andersen | 1a834be | 2004-01-30 22:59:50 +0000 | [diff] [blame] | 55 | uint32_t ipx_net; |
| 56 | uint8_t ipx_node[IPX_NODE_LEN]; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Denis Vlasenko | 98ee06d | 2006-12-31 18:57:37 +0000 | [diff] [blame] | 59 | extern uint32_t get_addr32(char *name); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 60 | extern int get_addr_1(inet_prefix *dst, char *arg, int family); |
| 61 | extern int get_prefix_1(inet_prefix *dst, char *arg, int family); |
| 62 | extern int get_addr(inet_prefix *dst, char *arg, int family); |
| 63 | extern int get_prefix(inet_prefix *dst, char *arg, int family); |
| 64 | |
| 65 | extern int get_integer(int *val, char *arg, int base); |
| 66 | extern int get_unsigned(unsigned *val, char *arg, int base); |
| 67 | #define get_byte get_u8 |
| 68 | #define get_ushort get_u16 |
| 69 | #define get_short get_s16 |
Denis Vlasenko | 98ee06d | 2006-12-31 18:57:37 +0000 | [diff] [blame] | 70 | extern int get_u32(uint32_t *val, char *arg, int base); |
| 71 | extern int get_u16(uint16_t *val, char *arg, int base); |
| 72 | extern int get_s16(int16_t *val, char *arg, int base); |
| 73 | extern int get_u8(uint8_t *val, char *arg, int base); |
| 74 | extern int get_s8(int8_t *val, char *arg, int base); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 75 | |
| 76 | extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); |
| 77 | extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen); |
| 78 | |
Bernhard Reutner-Fischer | f1bd42a | 2006-06-14 16:51:50 +0000 | [diff] [blame] | 79 | void invarg(const char * const, const char * const) ATTRIBUTE_NORETURN; |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 80 | void duparg(char *, char *) ATTRIBUTE_NORETURN; |
| 81 | void duparg2(char *, char *) ATTRIBUTE_NORETURN; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 82 | int matches(char *arg, char *pattern); |
| 83 | extern int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits); |
| 84 | |
| 85 | const char *dnet_ntop(int af, const void *addr, char *str, size_t len); |
| 86 | int dnet_pton(int af, const char *src, void *addr); |
| 87 | |
| 88 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len); |
| 89 | int ipx_pton(int af, const char *src, void *addr); |
| 90 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 91 | #endif /* __UTILS_H__ */ |