socks_proto.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @file socks_proto.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. * @section DESCRIPTION
  30. *
  31. * Definitions for the SOCKS protocol.
  32. */
  33. #ifndef BADVPN_MISC_SOCKS_PROTO_H
  34. #define BADVPN_MISC_SOCKS_PROTO_H
  35. #include <stdint.h>
  36. #include <misc/packed.h>
  37. #define SOCKS_VERSION 0x05
  38. #define SOCKS_METHOD_NO_AUTHENTICATION_REQUIRED 0x00
  39. #define SOCKS_METHOD_GSSAPI 0x01
  40. #define SOCKS_METHOD_USERNAME_PASSWORD 0x02
  41. #define SOCKS_METHOD_NO_ACCEPTABLE_METHODS 0xFF
  42. #define SOCKS_CMD_CONNECT 0x01
  43. #define SOCKS_CMD_BIND 0x02
  44. #define SOCKS_CMD_UDP_ASSOCIATE 0x03
  45. #define SOCKS_ATYP_IPV4 0x01
  46. #define SOCKS_ATYP_DOMAINNAME 0x03
  47. #define SOCKS_ATYP_IPV6 0x04
  48. #define SOCKS_REP_SUCCEEDED 0x00
  49. #define SOCKS_REP_GENERAL_FAILURE 0x01
  50. #define SOCKS_REP_CONNECTION_NOT_ALLOWED 0x02
  51. #define SOCKS_REP_NETWORK_UNREACHABLE 0x03
  52. #define SOCKS_REP_HOST_UNREACHABLE 0x04
  53. #define SOCKS_REP_CONNECTION_REFUSED 0x05
  54. #define SOCKS_REP_TTL_EXPIRED 0x06
  55. #define SOCKS_REP_COMMAND_NOT_SUPPORTED 0x07
  56. #define SOCKS_REP_ADDRESS_TYPE_NOT_SUPPORTED 0x08
  57. B_START_PACKED
  58. struct socks_client_hello_header {
  59. uint8_t ver;
  60. uint8_t nmethods;
  61. } B_PACKED;
  62. B_END_PACKED
  63. B_START_PACKED
  64. struct socks_client_hello_method {
  65. uint8_t method;
  66. } B_PACKED;
  67. B_END_PACKED
  68. B_START_PACKED
  69. struct socks_server_hello {
  70. uint8_t ver;
  71. uint8_t method;
  72. } B_PACKED;
  73. B_END_PACKED
  74. B_START_PACKED
  75. struct socks_request_header {
  76. uint8_t ver;
  77. uint8_t cmd;
  78. uint8_t rsv;
  79. uint8_t atyp;
  80. } B_PACKED;
  81. B_END_PACKED
  82. B_START_PACKED
  83. struct socks_reply_header {
  84. uint8_t ver;
  85. uint8_t rep;
  86. uint8_t rsv;
  87. uint8_t atyp;
  88. } B_PACKED;
  89. B_END_PACKED
  90. B_START_PACKED
  91. struct socks_addr_ipv4 {
  92. uint32_t addr;
  93. uint16_t port;
  94. } B_PACKED;
  95. B_END_PACKED
  96. B_START_PACKED
  97. struct socks_addr_ipv6 {
  98. uint8_t addr[16];
  99. uint16_t port;
  100. } B_PACKED;
  101. B_END_PACKED
  102. #endif