utils.h 2.6 KB

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