BSocksClient.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @file BSocksClient.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * SOCKS5 client. TCP only, no authentication.
  25. */
  26. #ifndef BADVPN_SOCKS_BSOCKSCLIENT_H
  27. #define BADVPN_SOCKS_BSOCKSCLIENT_H
  28. #include <stdint.h>
  29. #include <misc/debug.h>
  30. #include <misc/dead.h>
  31. #include <misc/socks_proto.h>
  32. #include <system/DebugObject.h>
  33. #include <system/BSocket.h>
  34. #include <flow/StreamSocketSink.h>
  35. #include <flow/StreamSocketSource.h>
  36. #include <flow/PacketStreamSender.h>
  37. #define BSOCKSCLIENT_EVENT_ERROR 1
  38. #define BSOCKSCLIENT_EVENT_UP 2
  39. #define BSOCKSCLIENT_EVENT_ERROR_CLOSED 3
  40. typedef void (*BSocksClient_handler) (void *user, int event);
  41. typedef struct {
  42. BAddr dest_addr;
  43. BSocksClient_handler handler;
  44. void *user;
  45. BReactor *reactor;
  46. int state;
  47. FlowErrorDomain domain;
  48. BSocket sock;
  49. union {
  50. struct {
  51. PacketPassInterface *send_if;
  52. PacketStreamSender send_sender;
  53. StreamSocketSink send_sink;
  54. StreamSocketSource recv_source;
  55. StreamRecvInterface *recv_if;
  56. union {
  57. struct {
  58. struct socks_client_hello_header header;
  59. struct socks_client_hello_method method;
  60. } __attribute__((packed)) client_hello;
  61. struct socks_server_hello server_hello;
  62. struct {
  63. struct socks_request_header header;
  64. union {
  65. struct socks_addr_ipv4 ipv4;
  66. struct socks_addr_ipv6 ipv6;
  67. } addr;
  68. } __attribute__((packed)) request;
  69. struct {
  70. struct socks_reply_header header;
  71. union {
  72. struct socks_addr_ipv4 ipv4;
  73. struct socks_addr_ipv6 ipv6;
  74. } addr;
  75. } __attribute__((packed)) reply;
  76. } msg;
  77. uint8_t *recv_dest;
  78. int recv_len;
  79. int recv_total;
  80. } control;
  81. struct {
  82. StreamSocketSink send_sink;
  83. StreamSocketSource recv_source;
  84. } up;
  85. };
  86. DebugObject d_obj;
  87. #ifndef NDEBUG
  88. dead_t d_dead;
  89. #endif
  90. } BSocksClient;
  91. int BSocksClient_Init (BSocksClient *o, BAddr server_addr, BAddr dest_addr, BSocksClient_handler handler, void *user, BReactor *reactor) WARN_UNUSED;
  92. void BSocksClient_Free (BSocksClient *o);
  93. StreamPassInterface * BSocksClient_GetSendInterface (BSocksClient *o);
  94. StreamRecvInterface * BSocksClient_GetRecvInterface (BSocksClient *o);
  95. #endif