blob: cd650492da913b9b85c8ae640325c864281dc2a5 [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 Vlasenkoed6a49c2007-11-18 22:56:25 +00009extern family_t preferred_family;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000010extern smallint show_stats; /* UNUSED */
11extern smallint show_details; /* UNUSED */
12extern smallint show_raw; /* UNUSED */
13extern smallint resolve_hosts; /* UNUSED */
14extern smallint oneline;
15extern char _SL_;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000016
17#ifndef IPPROTO_ESP
18#define IPPROTO_ESP 50
19#endif
20#ifndef IPPROTO_AH
21#define IPPROTO_AH 51
22#endif
23
24#define SPRINT_BSIZE 64
25#define SPRINT_BUF(x) char x[SPRINT_BSIZE]
26
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000027extern void incomplete_command(void) ATTRIBUTE_NORETURN;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000028
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000029#define NEXT_ARG() do { if (!*++argv) incomplete_command(); } while (0)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000030
31typedef struct
32{
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000033 uint8_t family;
34 uint8_t bytelen;
35 int16_t bitlen;
36 uint32_t data[4];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000037} inet_prefix;
38
39#define DN_MAXADDL 20
40#ifndef AF_DECnet
41#define AF_DECnet 12
42#endif
43
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000044struct dn_naddr {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000045 unsigned short a_len;
46 unsigned char a_addr[DN_MAXADDL];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000047};
48
49#define IPX_NODE_LEN 6
50
51struct ipx_addr {
Eric Andersen1a834be2004-01-30 22:59:50 +000052 uint32_t ipx_net;
53 uint8_t ipx_node[IPX_NODE_LEN];
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000054};
55
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000056extern uint32_t get_addr32(char *name);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000057extern int get_addr_1(inet_prefix *dst, char *arg, int family);
58extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
59extern int get_addr(inet_prefix *dst, char *arg, int family);
60extern int get_prefix(inet_prefix *dst, char *arg, int family);
61
62extern int get_integer(int *val, char *arg, int base);
63extern int get_unsigned(unsigned *val, char *arg, int base);
64#define get_byte get_u8
65#define get_ushort get_u16
66#define get_short get_s16
Denis Vlasenko98ee06d2006-12-31 18:57:37 +000067extern int get_u32(uint32_t *val, char *arg, int base);
68extern int get_u16(uint16_t *val, char *arg, int base);
69extern int get_s16(int16_t *val, char *arg, int base);
70extern int get_u8(uint8_t *val, char *arg, int base);
71extern int get_s8(int8_t *val, char *arg, int base);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000072
73extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
74extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen);
75
Denis Vlasenkoab2aea42007-01-29 22:51:58 +000076void invarg(const char *, const char *) ATTRIBUTE_NORETURN;
77void duparg(const char *, const char *) ATTRIBUTE_NORETURN;
78void duparg2(const char *, const char *) ATTRIBUTE_NORETURN;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000079int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000080
81const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
82int dnet_pton(int af, const char *src, void *addr);
83
84const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
85int ipx_pton(int af, const char *src, void *addr);
86
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000087#endif /* __UTILS_H__ */