utils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * netlink/utils.h Utility Functions
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_UTILS_H_
  12. #define NETLINK_UTILS_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/list.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * @name Probability Constants
  20. * @{
  21. */
  22. /**
  23. * Lower probability limit
  24. * @ingroup utils
  25. */
  26. #define NL_PROB_MIN 0x0
  27. /**
  28. * Upper probability limit
  29. * @ingroup utils
  30. */
  31. #define NL_PROB_MAX 0xffffffff
  32. /** @} */
  33. extern char * nl_geterror(void);
  34. extern int nl_get_errno(void);
  35. extern void nl_perror(const char *);
  36. /* unit pretty-printing */
  37. extern double nl_cancel_down_bytes(unsigned long long, char **);
  38. extern double nl_cancel_down_bits(unsigned long long, char **);
  39. extern double nl_cancel_down_us(uint32_t, char **);
  40. /* generic unit translations */
  41. extern long nl_size2int(const char *);
  42. extern long nl_prob2int(const char *);
  43. /* time translations */
  44. extern int nl_get_hz(void);
  45. extern uint32_t nl_us2ticks(uint32_t);
  46. extern uint32_t nl_ticks2us(uint32_t);
  47. extern char * nl_msec2str(uint64_t, char *, size_t);
  48. /* link layer protocol translations */
  49. extern char * nl_llproto2str(int, char *, size_t);
  50. extern int nl_str2llproto(const char *);
  51. /* ethernet protocol translations */
  52. extern char * nl_ether_proto2str(int, char *, size_t);
  53. extern int nl_str2ether_proto(const char *);
  54. /* IP protocol translations */
  55. extern char * nl_ip_proto2str(int, char *, size_t);
  56. extern int nl_str2ip_proto(const char *);
  57. /* Dumping helpers */
  58. extern void nl_new_line(struct nl_dump_params *, int);
  59. extern void nl_dump(struct nl_dump_params *, const char *, ...);
  60. extern void nl_dump_line(struct nl_dump_params *, int, const char *, ...);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif