ua_architecture.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <../deps/queue.h> //in some compilers there's already a _SYS_QUEUE_H_ who is included first and doesn't have all functions
  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. #else /* UA_sleep_ms */
  34. /* With this one can define its own UA_sleep_ms using a preprocessor define.
  35. E.g. see unit tests. */
  36. void UA_sleep_ms(size_t ms);
  37. #endif
  38. #define OPTVAL_TYPE int
  39. #include <fcntl.h>
  40. #include <unistd.h> // read, write, close
  41. #ifdef __QNX__
  42. # include <sys/socket.h>
  43. #endif
  44. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  45. # include <sys/param.h>
  46. # if defined(BSD)
  47. # include<sys/socket.h>
  48. # endif
  49. #endif
  50. #if !defined(__CYGWIN__)
  51. # include <netinet/tcp.h>
  52. #endif
  53. /* unsigned int for windows and workaround to a glibc bug */
  54. /* Additionally if GNU_LIBRARY is not defined, it may be using
  55. * musl libc (e.g. Docker Alpine) */
  56. #if defined(__OpenBSD__) || \
  57. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  58. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  59. !defined(__GNU_LIBRARY__))
  60. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  61. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  62. #else
  63. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  64. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  65. #endif
  66. #define UA_access access
  67. #define UA_IPV6 1
  68. #define UA_SOCKET int
  69. #define UA_INVALID_SOCKET -1
  70. #define UA_ERRNO errno
  71. #define UA_INTERRUPTED EINTR
  72. #define UA_AGAIN EAGAIN
  73. #define UA_EAGAIN EAGAIN
  74. #define UA_WOULDBLOCK EWOULDBLOCK
  75. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  76. #define UA_ENABLE_LOG_COLORS
  77. #define UA_getnameinfo getnameinfo
  78. #define UA_send send
  79. #define UA_recv recv
  80. #define UA_sendto sendto
  81. #define UA_recvfrom recvfrom
  82. #define UA_htonl htonl
  83. #define UA_ntohl ntohl
  84. #define UA_close close
  85. #define UA_select select
  86. #define UA_shutdown shutdown
  87. #define UA_socket socket
  88. #define UA_bind bind
  89. #define UA_listen listen
  90. #define UA_accept accept
  91. #define UA_connect connect
  92. #define UA_getaddrinfo getaddrinfo
  93. #define UA_getsockopt getsockopt
  94. #define UA_setsockopt setsockopt
  95. #define UA_freeaddrinfo freeaddrinfo
  96. #define UA_gethostname gethostname
  97. #define UA_inet_pton inet_pton
  98. #if UA_IPV6
  99. # define UA_if_nametoindex if_nametoindex
  100. #endif
  101. #include <stdlib.h>
  102. #define UA_free free
  103. #define UA_malloc malloc
  104. #define UA_calloc calloc
  105. #define UA_realloc realloc
  106. #include <stdio.h>
  107. #define UA_snprintf snprintf
  108. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  109. char *errno_str = strerror(errno); \
  110. LOG; \
  111. }
  112. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
  113. const char *errno_str = gai_strerror(errno); \
  114. LOG; \
  115. }
  116. #include "../ua_architecture_functions.h"
  117. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */
  118. #endif /* UA_ARCHITECTURE_POSIX */