blob: 55490980d533ac56d973993aadf963c98c98b96c [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
Denys Vlasenkofb132e42010-10-29 11:46:52 +020020#define IPPROTO_ESP 50
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000021#endif
22#ifndef IPPROTO_AH
Denys Vlasenkofb132e42010-10-29 11:46:52 +020023#define IPPROTO_AH 51
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000024#endif
25
26#define SPRINT_BSIZE 64
Denys Vlasenkofb132e42010-10-29 11:46:52 +020027#define SPRINT_BUF(x) char x[SPRINT_BSIZE]
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000028
Denis Vlasenko3e57adb2008-05-31 07:33:18 +000029typedef struct {
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000030 uint8_t family;
31 uint8_t bytelen;
32 int16_t bitlen;
33 uint32_t data[4];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034} inet_prefix;
35
Bernhard Reutner-Fischer8fbd8ac2008-10-21 12:42:45 +000036#define PREFIXLEN_SPECIFIED 1
37
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038#define DN_MAXADDL 20
39#ifndef AF_DECnet
40#define AF_DECnet 12
41#endif
42
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000043struct dn_naddr {
Denis Vlasenko284d0fa2008-02-16 13:18:17 +000044 unsigned short a_len;
45 unsigned char a_addr[DN_MAXADDL];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000046};
47
48#define IPX_NODE_LEN 6
49
50struct ipx_addr {
Eric Andersen1a834be2004-01-30 22:59:50 +000051 uint32_t ipx_net;
52 uint8_t ipx_node[IPX_NODE_LEN];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000053};
54
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020055char** next_arg(char **argv) FAST_FUNC;
56#define NEXT_ARG() do { argv = next_arg(argv); } while (0)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000057
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020058uint32_t get_addr32(char *name) FAST_FUNC;
59int 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;*/
61int get_addr(inet_prefix *dst, char *arg, int family) FAST_FUNC;
62void get_prefix(inet_prefix *dst, char *arg, int family) FAST_FUNC;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000063
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020064unsigned get_unsigned(char *arg, const char *errmsg) FAST_FUNC;
65uint32_t get_u32(char *arg, const char *errmsg) FAST_FUNC;
66uint16_t get_u16(char *arg, const char *errmsg) FAST_FUNC;
67
68const char *rt_addr_n2a(int af, void *addr) FAST_FUNC;
Denis Vlasenko76140a72009-03-05 09:21:57 +000069#ifdef RESOLVE_HOSTNAMES
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020070const char *format_host(int af, int len, void *addr) FAST_FUNC;
Denis Vlasenko76140a72009-03-05 09:21:57 +000071#else
Denys Vlasenko926d8012015-10-14 13:56:42 +020072#define format_host(af, len, addr) \
73 rt_addr_n2a(af, addr)
Denis Vlasenko76140a72009-03-05 09:21:57 +000074#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000075
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020076void invarg_1_to_2(const char *, const char *) FAST_FUNC NORETURN;
77void duparg(const char *, const char *) FAST_FUNC NORETURN;
78void duparg2(const char *, const char *) FAST_FUNC NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000079
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020080int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) FAST_FUNC;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000081
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020082//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 McGrath9a2d2722002-11-10 01:33:55 +000084
Denys Vlasenko826bdcd2017-04-07 17:15:40 +020085//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
88unsigned get_hz(void) FAST_FUNC;
Curt Brune69934702015-10-14 12:53:47 +020089
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000090POP_SAVED_FUNCTION_VISIBILITY
Denis Vlasenko98636eb2008-05-09 17:59:34 +000091
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000092#endif