ua_lwip.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 2018 (c) Jose Cabral, fortiss GmbH
  5. */
  6. #ifndef ARCH_COMMON_LWIP62541_H_
  7. #define ARCH_COMMON_LWIP62541_H_
  8. /*
  9. * Needed flags to be set before including this file. Normally done in lwipopts.h
  10. * #define LWIP_COMPAT_SOCKETS 0 // Don't do name define-transformation in networking function names.
  11. * #define LWIP_SOCKET 1 // Enable Socket API (normally already set)
  12. * #define LWIP_DNS 1 // enable the lwip_getaddrinfo function, struct addrinfo and more.
  13. * #define SO_REUSE 1 // Allows to set the socket as reusable
  14. * #define LWIP_TIMEVAL_PRIVATE 0 // This is optional. Set this flag if you get a compilation error about redefinition of struct timeval
  15. *
  16. * Why not define these here? This stack is used as middleware so other code might use this header file with other flags (specially LWIP_COMPAT_SOCKETS)
  17. */
  18. #include <lwip/tcpip.h>
  19. #include <lwip/netdb.h>
  20. #include <lwip/init.h>
  21. #include <lwip/sockets.h>
  22. #define OPTVAL_TYPE int
  23. #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  24. #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  25. #define UA_IPV6 LWIP_IPV6
  26. #define UA_SOCKET int
  27. #define UA_INVALID_SOCKET -1
  28. #define UA_ERRNO errno
  29. #define UA_INTERRUPTED EINTR
  30. #define UA_AGAIN EAGAIN
  31. #define UA_EAGAIN EAGAIN
  32. #define UA_WOULDBLOCK EWOULDBLOCK
  33. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  34. #define UA_send lwip_send
  35. #define UA_recv lwip_recv
  36. #define UA_sendto lwip_sendto
  37. #define UA_recvfrom lwip_recvfrom
  38. #define UA_htonl lwip_htonl
  39. #define UA_ntohl lwip_ntohl
  40. #define UA_close lwip_close
  41. #define UA_select lwip_select
  42. #define UA_shutdown lwip_shutdown
  43. #define UA_socket lwip_socket
  44. #define UA_bind lwip_bind
  45. #define UA_listen lwip_listen
  46. #define UA_accept lwip_accept
  47. #define UA_connect lwip_connect
  48. #define UA_getsockopt lwip_getsockopt
  49. #define UA_setsockopt lwip_setsockopt
  50. #define UA_freeaddrinfo lwip_freeaddrinfo
  51. #define UA_gethostname gethostname_lwip
  52. #define UA_getsockname lwip_getsockname
  53. #define UA_getaddrinfo lwip_getaddrinfo
  54. #if UA_IPV6
  55. # define UA_inet_pton(af, src, dst) \
  56. (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) \
  57. : (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0))
  58. #else
  59. # define UA_inet_pton(af, src, dst) \
  60. (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
  61. #endif
  62. #if UA_IPV6
  63. # define UA_if_nametoindex lwip_if_nametoindex
  64. # if LWIP_VERSION_IS_RELEASE //lwip_if_nametoindex is not yet released
  65. unsigned int lwip_if_nametoindex(const char *ifname);
  66. # endif
  67. #endif
  68. int gethostname_lwip(char* name, size_t len); //gethostname is not present in LwIP. We implement here a dummy. See ../freertosLWIP/ua_architecture_functions.c
  69. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
  70. #endif /* ARCH_COMMON_LWIP62541_H_ */