ua_architecture.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include "ua_architecture_base.h"
  11. /* Enable POSIX features */
  12. #if !defined(_XOPEN_SOURCE)
  13. # define _XOPEN_SOURCE 600
  14. #endif
  15. #ifndef _DEFAULT_SOURCE
  16. # define _DEFAULT_SOURCE
  17. #endif
  18. /* On older systems we need to define _BSD_SOURCE.
  19. * _DEFAULT_SOURCE is an alias for that. */
  20. #ifndef _BSD_SOURCE
  21. # define _BSD_SOURCE
  22. #endif
  23. #include <errno.h>
  24. #include <arpa/inet.h>
  25. #include <netinet/in.h>
  26. #include <netdb.h>
  27. #include <sys/ioctl.h>
  28. #include <sys/select.h>
  29. #include <sys/types.h>
  30. #include <net/if.h>
  31. #ifndef UA_sleep_ms
  32. # include <unistd.h>
  33. # define UA_sleep_ms(X) usleep(X * 1000)
  34. #endif
  35. #define OPTVAL_TYPE int
  36. #include <fcntl.h>
  37. #include <unistd.h> // read, write, close
  38. #ifdef __QNX__
  39. # include <sys/socket.h>
  40. #endif
  41. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  42. # include <sys/param.h>
  43. # if defined(BSD)
  44. # include<sys/socket.h>
  45. # endif
  46. #endif
  47. #if !defined(__CYGWIN__)
  48. # include <netinet/tcp.h>
  49. #endif
  50. /* unsigned int for windows and workaround to a glibc bug */
  51. /* Additionally if GNU_LIBRARY is not defined, it may be using
  52. * musl libc (e.g. Docker Alpine) */
  53. #if defined(__OpenBSD__) || \
  54. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  55. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  56. !defined(__GNU_LIBRARY__))
  57. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  58. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  59. #else
  60. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  61. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  62. #endif
  63. #define UA_access access
  64. #define UA_IPV6 1
  65. #define UA_SOCKET int
  66. #define UA_INVALID_SOCKET -1
  67. #define UA_ERRNO errno
  68. #define UA_INTERRUPTED EINTR
  69. #define UA_AGAIN EAGAIN
  70. #define UA_EAGAIN EAGAIN
  71. #define UA_WOULDBLOCK EWOULDBLOCK
  72. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  73. #define UA_ENABLE_LOG_COLORS
  74. #define UA_getnameinfo getnameinfo
  75. #define UA_send send
  76. #define UA_recv recv
  77. #define UA_sendto sendto
  78. #define UA_recvfrom recvfrom
  79. #define UA_htonl htonl
  80. #define UA_ntohl ntohl
  81. #define UA_close close
  82. #define UA_select select
  83. #define UA_shutdown shutdown
  84. #define UA_socket socket
  85. #define UA_bind bind
  86. #define UA_listen listen
  87. #define UA_accept accept
  88. #define UA_connect connect
  89. #define UA_getaddrinfo getaddrinfo
  90. #define UA_getsockopt getsockopt
  91. #define UA_setsockopt setsockopt
  92. #define UA_freeaddrinfo freeaddrinfo
  93. #define UA_gethostname gethostname
  94. #define UA_inet_pton inet_pton
  95. #if UA_IPV6
  96. # define UA_if_nametoindex if_nametoindex
  97. #endif
  98. #include <stdlib.h>
  99. #ifndef UA_free
  100. #define UA_free free
  101. #endif
  102. #ifndef UA_malloc
  103. #define UA_malloc malloc
  104. #endif
  105. #ifndef UA_calloc
  106. #define UA_calloc calloc
  107. #endif
  108. #ifndef UA_realloc
  109. #define UA_realloc realloc
  110. #endif
  111. #include <stdio.h>
  112. #define UA_snprintf snprintf
  113. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  114. char *errno_str = strerror(errno); \
  115. LOG; \
  116. }
  117. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
  118. const char *errno_str = gai_strerror(errno); \
  119. LOG; \
  120. }
  121. #include "ua_architecture_functions.h"
  122. #if defined(__APPLE__) && defined(_SYS_QUEUE_H_)
  123. // in some compilers there's already a _SYS_QUEUE_H_ which is included first and doesn't have all functions
  124. #undef SLIST_HEAD
  125. #undef SLIST_HEAD_INITIALIZER
  126. #undef SLIST_ENTRY
  127. #undef SLIST_FIRST
  128. #undef SLIST_END
  129. #undef SLIST_EMPTY
  130. #undef SLIST_NEXT
  131. #undef SLIST_FOREACH
  132. #undef SLIST_FOREACH_SAFE
  133. #undef SLIST_INIT
  134. #undef SLIST_INSERT_AFTER
  135. #undef SLIST_INSERT_HEAD
  136. #undef SLIST_REMOVE_AFTER
  137. #undef SLIST_REMOVE_HEAD
  138. #undef SLIST_REMOVE
  139. #undef LIST_HEAD
  140. #undef LIST_HEAD_INITIALIZER
  141. #undef LIST_ENTRY
  142. #undef LIST_FIRST
  143. #undef LIST_END
  144. #undef LIST_EMPTY
  145. #undef LIST_NEXT
  146. #undef LIST_FOREACH
  147. #undef LIST_FOREACH_SAFE
  148. #undef LIST_INIT
  149. #undef LIST_INSERT_AFTER
  150. #undef LIST_INSERT_BEFORE
  151. #undef LIST_INSERT_HEAD
  152. #undef LIST_REMOVE
  153. #undef LIST_REPLACE
  154. #undef SIMPLEQ_HEAD
  155. #undef SIMPLEQ_HEAD_INITIALIZER
  156. #undef SIMPLEQ_ENTRY
  157. #undef SIMPLEQ_FIRST
  158. #undef SIMPLEQ_END
  159. #undef SIMPLEQ_EMPTY
  160. #undef SIMPLEQ_NEXT
  161. #undef SIMPLEQ_FOREACH
  162. #undef SIMPLEQ_FOREACH_SAFE
  163. #undef SIMPLEQ_INIT
  164. #undef SIMPLEQ_INSERT_HEAD
  165. #undef SIMPLEQ_INSERT_TAIL
  166. #undef SIMPLEQ_INSERT_AFTER
  167. #undef SIMPLEQ_REMOVE_HEAD
  168. #undef SIMPLEQ_REMOVE_AFTER
  169. #undef XSIMPLEQ_HEAD
  170. #undef XSIMPLEQ_ENTRY
  171. #undef XSIMPLEQ_XOR
  172. #undef XSIMPLEQ_FIRST
  173. #undef XSIMPLEQ_END
  174. #undef XSIMPLEQ_EMPTY
  175. #undef XSIMPLEQ_NEXT
  176. #undef XSIMPLEQ_FOREACH
  177. #undef XSIMPLEQ_FOREACH_SAFE
  178. #undef XSIMPLEQ_INIT
  179. #undef XSIMPLEQ_INSERT_HEAD
  180. #undef XSIMPLEQ_INSERT_TAIL
  181. #undef XSIMPLEQ_INSERT_AFTER
  182. #undef XSIMPLEQ_REMOVE_HEAD
  183. #undef XSIMPLEQ_REMOVE_AFTER
  184. #undef TAILQ_HEAD
  185. #undef TAILQ_HEAD_INITIALIZER
  186. #undef TAILQ_ENTRY
  187. #undef TAILQ_FIRST
  188. #undef TAILQ_END
  189. #undef TAILQ_NEXT
  190. #undef TAILQ_LAST
  191. #undef TAILQ_PREV
  192. #undef TAILQ_EMPTY
  193. #undef TAILQ_FOREACH
  194. #undef TAILQ_FOREACH_SAFE
  195. #undef TAILQ_FOREACH_REVERSE
  196. #undef TAILQ_FOREACH_REVERSE_SAFE
  197. #undef TAILQ_INIT
  198. #undef TAILQ_INSERT_HEAD
  199. #undef TAILQ_INSERT_TAIL
  200. #undef TAILQ_INSERT_AFTER
  201. #undef TAILQ_INSERT_BEFORE
  202. #undef TAILQ_REMOVE
  203. #undef TAILQ_REPLACE
  204. #undef CIRCLEQ_HEAD
  205. #undef CIRCLEQ_HEAD_INITIALIZER
  206. #undef CIRCLEQ_ENTRY
  207. #undef CIRCLEQ_FIRST
  208. #undef CIRCLEQ_LAST
  209. #undef CIRCLEQ_END
  210. #undef CIRCLEQ_NEXT
  211. #undef CIRCLEQ_PREV
  212. #undef CIRCLEQ_EMPTY
  213. #undef CIRCLEQ_FOREACH
  214. #undef CIRCLEQ_FOREACH_SAFE
  215. #undef CIRCLEQ_FOREACH_REVERSE
  216. #undef CIRCLEQ_FOREACH_REVERSE_SAFE
  217. #undef CIRCLEQ_INIT
  218. #undef CIRCLEQ_INSERT_AFTER
  219. #undef CIRCLEQ_INSERT_BEFORE
  220. #undef CIRCLEQ_INSERT_HEAD
  221. #undef CIRCLEQ_INSERT_TAIL
  222. #undef CIRCLEQ_REMOVE
  223. #undef CIRCLEQ_REPLACE
  224. #undef _SYS_QUEUE_H_
  225. #endif /* defined(__APPLE__) && defined(_SYS_QUEUE_H_) */
  226. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */
  227. #endif /* UA_ARCHITECTURE_POSIX */