blob: ed03e785a9c14ceb26eb83ced92030a861281dd9 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Denis Vlasenkof81e8db2009-04-09 12:35:13 +00002#ifndef UTILS_H
3#define UTILS_H 1
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00004
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00005#include "libnetlink.h"
6#include "ll_map.h"
7#include "rtm_map.h"
8
Denis Vlasenkof81e8db2009-04-09 12:35:13 +00009PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
Denis Vlasenko98636eb2008-05-09 17:59:34 +000010
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000011extern family_t preferred_family;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000012extern smallint show_stats; /* UNUSED */
13extern smallint show_details; /* UNUSED */
14extern smallint show_raw; /* UNUSED */
15extern smallint resolve_hosts; /* UNUSED */
16extern smallint oneline;
17extern char _SL_;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000018
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
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000029extern void incomplete_command(void) NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000030
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000031#define NEXT_ARG() do { if (!*++argv) incomplete_command(); } while (0)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032
Denis Vlasenko3e57adb2008-05-31 07:33:18 +000033typedef struct {
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000034 uint8_t family;
35 uint8_t bytelen;
36 int16_t bitlen;
37 uint32_t data[4];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038} inet_prefix;
39
Bernhard Reutner-Fischer8fbd8ac2008-10-21 12:42:45 +000040#define PREFIXLEN_SPECIFIED 1
41
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000042#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);
Denis Vlasenko787a4922009-03-03 14:55:29 +000061/*extern int get_prefix_1(inet_prefix *dst, char *arg, int family);*/
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000062extern int get_addr(inet_prefix *dst, char *arg, int family);
63extern int get_prefix(inet_prefix *dst, char *arg, int family);
64
Denis Vlasenko76140a72009-03-05 09:21:57 +000065extern unsigned get_unsigned(char *arg, const char *errmsg);
66extern uint32_t get_u32(char *arg, const char *errmsg);
67extern uint16_t get_u16(char *arg, const char *errmsg);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000068
Denis Vlasenko76140a72009-03-05 09:21:57 +000069extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen);
70#ifdef RESOLVE_HOSTNAMES
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000071extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
Denis Vlasenko76140a72009-03-05 09:21:57 +000072#else
73#define format_host(af, len, addr, buf, buflen) \
74 rt_addr_n2a(af, addr, buf, buflen)
75#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000076
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000077void invarg(const char *, const char *) NORETURN;
78void duparg(const char *, const char *) NORETURN;
79void duparg2(const char *, const char *) NORETURN;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000080int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000081
82const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
83int dnet_pton(int af, const char *src, void *addr);
84
85const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
86int ipx_pton(int af, const char *src, void *addr);
87
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000088POP_SAVED_FUNCTION_VISIBILITY
Denis Vlasenko98636eb2008-05-09 17:59:34 +000089
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000090#endif