programs_helper.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright (c) 2019 Felix Weinrank
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #ifndef __PROGRAMS_HELPER_H__
  28. #define __PROGRAMS_HELPER_H__
  29. #ifndef _WIN32
  30. #define SCTP_PACKED __attribute__((packed))
  31. #else
  32. #pragma pack (push, 1)
  33. #define SCTP_PACKED
  34. #endif
  35. struct sctp_chunk_header {
  36. uint8_t chunk_type; /* chunk type */
  37. uint8_t chunk_flags; /* chunk flags */
  38. uint16_t chunk_length; /* chunk length */
  39. /* optional params follow */
  40. } SCTP_PACKED;
  41. struct sctp_init_chunk {
  42. struct sctp_chunk_header ch;
  43. uint32_t initiate_tag; /* initiate tag */
  44. uint32_t a_rwnd; /* a_rwnd */
  45. uint16_t num_outbound_streams; /* OS */
  46. uint16_t num_inbound_streams; /* MIS */
  47. uint32_t initial_tsn; /* I-TSN */
  48. /* optional param's follow */
  49. } SCTP_PACKED;
  50. #ifdef _WIN32
  51. #pragma pack(pop)
  52. #endif
  53. #undef SCTP_PACKED
  54. void
  55. handle_notification(union sctp_notification *notif, size_t n);
  56. #ifndef timersub
  57. #define timersub(tvp, uvp, vvp) \
  58. do { \
  59. (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
  60. (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
  61. if ((vvp)->tv_usec < 0) { \
  62. (vvp)->tv_sec--; \
  63. (vvp)->tv_usec += 1000000; \
  64. } \
  65. } while (0)
  66. #endif
  67. void
  68. debug_printf(const char *format, ...);
  69. void
  70. debug_printf_clean(const char *format, ...);
  71. void
  72. debug_printf_stack(const char *format, ...);
  73. void
  74. debug_set_target(FILE *fp);
  75. #endif /* __PROGRAMS_HELPER_H__ */