blob: 607083af8797c3708f94c238a47a86d40d411326 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00002#ifndef __UTILS_H__
3#define __UTILS_H__ 1
4
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00005#include "libnetlink.h"
6#include "ll_map.h"
7#include "rtm_map.h"
8
Denis Vlasenko98636eb2008-05-09 17:59:34 +00009#if __GNUC_PREREQ(4,1)
10# pragma GCC visibility push(hidden)
11#endif
12
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000013extern family_t preferred_family;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000014extern smallint show_stats; /* UNUSED */
15extern smallint show_details; /* UNUSED */
16extern smallint show_raw; /* UNUSED */
17extern smallint resolve_hosts; /* UNUSED */
18extern smallint oneline;
19extern char _SL_;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000020
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
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000031extern void incomplete_command(void) NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000033#define NEXT_ARG() do { if (!*++argv) incomplete_command(); } while (0)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034
Denis Vlasenko3e57adb2008-05-31 07:33:18 +000035typedef struct {
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000036 uint8_t family;
37 uint8_t bytelen;
38 int16_t bitlen;
39 uint32_t data[4];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000040} inet_prefix;
41
42#define DN_MAXADDL 20
43#ifndef AF_DECnet
44#define AF_DECnet 12
45#endif
46
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000047struct dn_naddr {
Denis Vlasenko284d0fa2008-02-16 13:18:17 +000048 unsigned short a_len;
49 unsigned char a_addr[DN_MAXADDL];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000050};
51
52#define IPX_NODE_LEN 6
53
54struct ipx_addr {
Eric Andersen1a834be2004-01-30 22:59:50 +000055 uint32_t ipx_net;
56 uint8_t ipx_node[IPX_NODE_LEN];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000057};
58
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000059extern uint32_t get_addr32(char *name);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000060extern int get_addr_1(inet_prefix *dst, char *arg, int family);
61extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
62extern int get_addr(inet_prefix *dst, char *arg, int family);
63extern int get_prefix(inet_prefix *dst, char *arg, int family);
64
65extern int get_integer(int *val, char *arg, int base);
66extern 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 Vlasenko98ee06d2006-12-31 18:57:37 +000070extern int get_u32(uint32_t *val, char *arg, int base);
71extern int get_u16(uint16_t *val, char *arg, int base);
72extern int get_s16(int16_t *val, char *arg, int base);
73extern int get_u8(uint8_t *val, char *arg, int base);
74extern int get_s8(int8_t *val, char *arg, int base);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000075
76extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
77extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen);
78
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000079void invarg(const char *, const char *) NORETURN;
80void duparg(const char *, const char *) NORETURN;
81void duparg2(const char *, const char *) NORETURN;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000082int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000083
84const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
85int dnet_pton(int af, const char *src, void *addr);
86
87const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
88int ipx_pton(int af, const char *src, void *addr);
89
Denis Vlasenko98636eb2008-05-09 17:59:34 +000090#if __GNUC_PREREQ(4,1)
91# pragma GCC visibility pop
92#endif
93
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000094#endif /* __UTILS_H__ */