utils.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2012 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 nl_dump_type
  29. * @ingroup utils
  30. */
  31. #define NL_PROB_MAX 0xffffffff
  32. /** @} */
  33. enum {
  34. NL_BYTE_RATE,
  35. NL_BIT_RATE,
  36. };
  37. /* unit pretty-printing */
  38. extern double nl_cancel_down_bytes(unsigned long long, char **);
  39. extern double nl_cancel_down_bits(unsigned long long, char **);
  40. extern int nl_rate2str(unsigned long long, int, char *, size_t);
  41. extern double nl_cancel_down_us(uint32_t, char **);
  42. /* generic unit translations */
  43. extern long nl_size2int(const char *);
  44. extern char * nl_size2str(const size_t, char *, const size_t);
  45. extern long nl_prob2int(const char *);
  46. /* time translations */
  47. extern int nl_get_user_hz(void);
  48. extern int nl_get_psched_hz(void);
  49. extern uint32_t nl_us2ticks(uint32_t);
  50. extern uint32_t nl_ticks2us(uint32_t);
  51. extern int nl_str2msec(const char *, uint64_t *);
  52. extern char * nl_msec2str(uint64_t, char *, size_t);
  53. /* link layer protocol translations */
  54. extern char * nl_llproto2str(int, char *, size_t);
  55. extern int nl_str2llproto(const char *);
  56. /* ethernet protocol translations */
  57. extern char * nl_ether_proto2str(int, char *, size_t);
  58. extern int nl_str2ether_proto(const char *);
  59. /* IP protocol translations */
  60. extern char * nl_ip_proto2str(int, char *, size_t);
  61. extern int nl_str2ip_proto(const char *);
  62. /* Dumping helpers */
  63. extern void nl_new_line(struct nl_dump_params *);
  64. extern void nl_dump(struct nl_dump_params *, const char *, ...);
  65. extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif