utils.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* vi: set sw=4 ts=4: */
  2. #ifndef __UTILS_H__
  3. #define __UTILS_H__ 1
  4. #include "libnetlink.h"
  5. #include "ll_map.h"
  6. #include "rtm_map.h"
  7. extern family_t preferred_family;
  8. extern smallint show_stats; /* UNUSED */
  9. extern smallint show_details; /* UNUSED */
  10. extern smallint show_raw; /* UNUSED */
  11. extern smallint resolve_hosts; /* UNUSED */
  12. extern smallint oneline;
  13. extern char _SL_;
  14. #ifndef IPPROTO_ESP
  15. #define IPPROTO_ESP 50
  16. #endif
  17. #ifndef IPPROTO_AH
  18. #define IPPROTO_AH 51
  19. #endif
  20. #define SPRINT_BSIZE 64
  21. #define SPRINT_BUF(x) char x[SPRINT_BSIZE]
  22. extern void incomplete_command(void) ATTRIBUTE_NORETURN;
  23. #define NEXT_ARG() do { if (!*++argv) incomplete_command(); } while (0)
  24. typedef struct
  25. {
  26. uint8_t family;
  27. uint8_t bytelen;
  28. int16_t bitlen;
  29. uint32_t data[4];
  30. } inet_prefix;
  31. #define DN_MAXADDL 20
  32. #ifndef AF_DECnet
  33. #define AF_DECnet 12
  34. #endif
  35. struct dn_naddr {
  36. unsigned short a_len;
  37. unsigned char a_addr[DN_MAXADDL];
  38. };
  39. #define IPX_NODE_LEN 6
  40. struct ipx_addr {
  41. uint32_t ipx_net;
  42. uint8_t ipx_node[IPX_NODE_LEN];
  43. };
  44. extern uint32_t get_addr32(char *name);
  45. extern int get_addr_1(inet_prefix *dst, char *arg, int family);
  46. extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
  47. extern int get_addr(inet_prefix *dst, char *arg, int family);
  48. extern int get_prefix(inet_prefix *dst, char *arg, int family);
  49. extern int get_integer(int *val, char *arg, int base);
  50. extern int get_unsigned(unsigned *val, char *arg, int base);
  51. #define get_byte get_u8
  52. #define get_ushort get_u16
  53. #define get_short get_s16
  54. extern int get_u32(uint32_t *val, char *arg, int base);
  55. extern int get_u16(uint16_t *val, char *arg, int base);
  56. extern int get_s16(int16_t *val, char *arg, int base);
  57. extern int get_u8(uint8_t *val, char *arg, int base);
  58. extern int get_s8(int8_t *val, char *arg, int base);
  59. extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
  60. extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen);
  61. void invarg(const char *, const char *) ATTRIBUTE_NORETURN;
  62. void duparg(const char *, const char *) ATTRIBUTE_NORETURN;
  63. void duparg2(const char *, const char *) ATTRIBUTE_NORETURN;
  64. int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
  65. const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
  66. int dnet_pton(int af, const char *src, void *addr);
  67. const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
  68. int ipx_pton(int af, const char *src, void *addr);
  69. #endif /* __UTILS_H__ */