ua_architecture.h 5.8 KB

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