cc.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file cc.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions 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. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef LWIP_CUSTOM_CC_H
  30. #define LWIP_CUSTOM_CC_H
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <errno.h>
  34. #include <stdint.h>
  35. #include <misc/debug.h>
  36. #include <misc/byteorder.h>
  37. #include <misc/packed.h>
  38. #include <misc/print_macros.h>
  39. #include <misc/byteorder.h>
  40. #include <base/BLog.h>
  41. #define PACK_STRUCT_BEGIN B_START_PACKED
  42. #define PACK_STRUCT_END B_END_PACKED
  43. #define PACK_STRUCT_STRUCT B_PACKED
  44. #define LWIP_PLATFORM_DIAG(x) { if (BLog_WouldLog(BLOG_CHANNEL_lwip, BLOG_INFO)) { BLog_Begin(); BLog_Append x; BLog_Finish(BLOG_CHANNEL_lwip, BLOG_INFO); } }
  45. #define LWIP_PLATFORM_ASSERT(x) { fprintf(stderr, "%s: lwip assertion failure: %s\n", __FUNCTION__, (x)); abort(); }
  46. #define lwip_htons(x) hton16(x)
  47. #define lwip_htonl(x) hton32(x)
  48. #define LWIP_RAND() ( \
  49. (((uint32_t)(rand() & 0xFF)) << 24) | \
  50. (((uint32_t)(rand() & 0xFF)) << 16) | \
  51. (((uint32_t)(rand() & 0xFF)) << 8) | \
  52. (((uint32_t)(rand() & 0xFF)) << 0) \
  53. )
  54. // for BYTE_ORDER
  55. #if defined(BADVPN_USE_WINAPI) && !defined(_MSC_VER)
  56. #include <sys/param.h>
  57. #elif defined(BADVPN_LINUX)
  58. #include <endian.h>
  59. #elif defined(BADVPN_FREEBSD)
  60. #include <machine/endian.h>
  61. #else
  62. #define LITTLE_ENDIAN 1234
  63. #define BIG_ENDIAN 4321
  64. #if defined(BADVPN_LITTLE_ENDIAN)
  65. #define BYTE_ORDER LITTLE_ENDIAN
  66. #else
  67. #define BYTE_ORDER BIG_ENDIAN
  68. #endif
  69. #endif
  70. #endif