ua_architecture.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
  5. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  6. */
  7. #ifdef UA_ARCHITECTURE_POSIX
  8. #ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  9. #define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  10. /* Enable POSIX features */
  11. #if !defined(_XOPEN_SOURCE)
  12. # define _XOPEN_SOURCE 600
  13. #endif
  14. #ifndef _DEFAULT_SOURCE
  15. # define _DEFAULT_SOURCE
  16. #endif
  17. /* On older systems we need to define _BSD_SOURCE.
  18. * _DEFAULT_SOURCE is an alias for that. */
  19. #ifndef _BSD_SOURCE
  20. # define _BSD_SOURCE
  21. #endif
  22. #include <errno.h>
  23. #include <arpa/inet.h>
  24. #include <netinet/in.h>
  25. #include <netdb.h>
  26. #include <sys/ioctl.h>
  27. #include <sys/select.h>
  28. #include <sys/types.h>
  29. #include <net/if.h>
  30. #ifndef UA_sleep_ms
  31. # define UA_sleep_ms(X) usleep(X * 1000)
  32. #else /* UA_sleep_ms */
  33. /* With this one can define its own UA_sleep_ms using a preprocessor define.
  34. E.g. see unit tests. */
  35. void UA_sleep_ms(size_t ms);
  36. #endif
  37. #define OPTVAL_TYPE int
  38. #include <fcntl.h>
  39. #include <unistd.h> // read, write, close
  40. #ifdef __QNX__
  41. # include <sys/socket.h>
  42. #endif
  43. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  44. # include <sys/param.h>
  45. # if defined(BSD)
  46. # include<sys/socket.h>
  47. # endif
  48. #endif
  49. #if !defined(__CYGWIN__)
  50. # include <netinet/tcp.h>
  51. #endif
  52. /* unsigned int for windows and workaround to a glibc bug */
  53. /* Additionally if GNU_LIBRARY is not defined, it may be using
  54. * musl libc (e.g. Docker Alpine) */
  55. #if defined(__OpenBSD__) || \
  56. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  57. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  58. !defined(__GNU_LIBRARY__))
  59. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  60. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  61. #else
  62. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  63. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  64. #endif
  65. #define UA_access access
  66. #define UA_IPV6 1
  67. #define UA_SOCKET int
  68. #define UA_INVALID_SOCKET -1
  69. #define UA_ERRNO errno
  70. #define UA_INTERRUPTED EINTR
  71. #define UA_AGAIN EAGAIN
  72. #define UA_EAGAIN EAGAIN
  73. #define UA_WOULDBLOCK EWOULDBLOCK
  74. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  75. #define UA_ENABLE_LOG_COLORS
  76. #define UA_getnameinfo getnameinfo
  77. #define UA_send send
  78. #define UA_recv recv
  79. #define UA_sendto sendto
  80. #define UA_recvfrom recvfrom
  81. #define UA_htonl htonl
  82. #define UA_ntohl ntohl
  83. #define UA_close close
  84. #define UA_select select
  85. #define UA_shutdown shutdown
  86. #define UA_socket socket
  87. #define UA_bind bind
  88. #define UA_listen listen
  89. #define UA_accept accept
  90. #define UA_connect connect
  91. #define UA_getaddrinfo getaddrinfo
  92. #define UA_getsockopt getsockopt
  93. #define UA_setsockopt setsockopt
  94. #define UA_freeaddrinfo freeaddrinfo
  95. #define UA_gethostname gethostname
  96. #define UA_inet_pton inet_pton
  97. #if UA_IPV6
  98. # define UA_if_nametoindex if_nametoindex
  99. #endif
  100. #include <stdlib.h>
  101. #define UA_free free
  102. #define UA_malloc malloc
  103. #define UA_calloc calloc
  104. #define UA_realloc realloc
  105. #include <stdio.h>
  106. #define UA_snprintf snprintf
  107. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  108. char *errno_str = strerror(errno); \
  109. LOG; \
  110. }
  111. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
  112. const char *errno_str = gai_strerror(errno); \
  113. LOG; \
  114. }
  115. #include "../ua_architecture_functions.h"
  116. #undef SLIST_EMPTY
  117. #undef SLIST_FOREACH
  118. #undef SLIST_INIT
  119. #undef SLIST_REMOVE
  120. #undef LIST_EMPTY
  121. #undef LIST_FOREACH
  122. #undef LIST_INIT
  123. #undef LIST_REMOVE
  124. #undef TAILQ_EMPTY
  125. #undef TAILQ_FOREACH
  126. #undef TAILQ_INIT
  127. #undef TAILQ_REMOVE
  128. #undef TAILQ_FOREACH_REVERSE
  129. #undef CIRCLEQ_EMPTY
  130. #undef CIRCLEQ_FOREACH
  131. #undef CIRCLEQ_INIT
  132. #undef CIRCLEQ_FOREACH_REVERSE
  133. #undef CIRCLEQ_REMOVE
  134. #undef CIRCLEQ_INSERT_TAIL
  135. #undef CIRCLEQ_INSERT_HEAD
  136. #undef CIRCLEQ_INSERT_AFTER
  137. #undef CIRCLEQ_INSERT_BEFORE
  138. #undef _SYS_QUEUE_H_
  139. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */
  140. #endif /* UA_ARCHITECTURE_POSIX */