ua_architecture.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #undef SLIST_EMPTY
  122. #undef SLIST_FOREACH
  123. #undef SLIST_INIT
  124. #undef SLIST_REMOVE
  125. #undef LIST_EMPTY
  126. #undef LIST_FOREACH
  127. #undef LIST_INIT
  128. #undef LIST_REMOVE
  129. #undef TAILQ_EMPTY
  130. #undef TAILQ_FOREACH
  131. #undef TAILQ_INIT
  132. #undef TAILQ_REMOVE
  133. #undef TAILQ_FOREACH_REVERSE
  134. #undef CIRCLEQ_EMPTY
  135. #undef CIRCLEQ_FOREACH
  136. #undef CIRCLEQ_INIT
  137. #undef CIRCLEQ_FOREACH_REVERSE
  138. #undef CIRCLEQ_REMOVE
  139. #undef CIRCLEQ_INSERT_TAIL
  140. #undef CIRCLEQ_INSERT_HEAD
  141. #undef CIRCLEQ_INSERT_AFTER
  142. #undef CIRCLEQ_INSERT_BEFORE
  143. #undef _SYS_QUEUE_H_
  144. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */
  145. #endif /* UA_ARCHITECTURE_POSIX */