BDatagram_win.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file BDatagram_win.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include <windows.h>
  30. #include <winsock2.h>
  31. #ifdef BADVPN_USE_SHIPPED_MSWSOCK
  32. # include <misc/mswsock.h>
  33. #else
  34. # include <mswsock.h>
  35. #endif
  36. #include <misc/debugerror.h>
  37. #include <base/DebugObject.h>
  38. struct BDatagram_sys_addr {
  39. int len;
  40. union {
  41. struct sockaddr generic;
  42. struct sockaddr_in ipv4;
  43. struct sockaddr_in6 ipv6;
  44. } addr;
  45. };
  46. struct BDatagram_s {
  47. BReactor *reactor;
  48. void *user;
  49. BDatagram_handler handler;
  50. SOCKET sock;
  51. LPFN_WSASENDMSG fnWSASendMsg;
  52. LPFN_WSARECVMSG fnWSARecvMsg;
  53. int aborted;
  54. struct {
  55. BReactorIOCPOverlapped olap;
  56. int have_addrs;
  57. BAddr remote_addr;
  58. BIPAddr local_addr;
  59. int inited;
  60. int mtu;
  61. PacketPassInterface iface;
  62. BPending job;
  63. int data_len;
  64. uint8_t *data;
  65. int data_busy;
  66. struct BDatagram_sys_addr sysaddr;
  67. union {
  68. char in[WSA_CMSG_SPACE(sizeof(struct in_pktinfo))];
  69. char in6[WSA_CMSG_SPACE(sizeof(struct in6_pktinfo))];
  70. } cdata;
  71. WSAMSG msg;
  72. } send;
  73. struct {
  74. BReactorIOCPOverlapped olap;
  75. int started;
  76. int have_addrs;
  77. BAddr remote_addr;
  78. BIPAddr local_addr;
  79. int inited;
  80. int mtu;
  81. PacketRecvInterface iface;
  82. BPending job;
  83. int data_have;
  84. uint8_t *data;
  85. int data_busy;
  86. struct BDatagram_sys_addr sysaddr;
  87. union {
  88. char in[WSA_CMSG_SPACE(sizeof(struct in_pktinfo))];
  89. char in6[WSA_CMSG_SPACE(sizeof(struct in6_pktinfo))];
  90. } cdata;
  91. WSAMSG msg;
  92. } recv;
  93. DebugError d_err;
  94. DebugObject d_obj;
  95. };