socks_proto.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define SOCKS_VERSION 0x05
  37. #define SOCKS_METHOD_NO_AUTHENTICATION_REQUIRED 0x00
  38. #define SOCKS_METHOD_GSSAPI 0x01
  39. #define SOCKS_METHOD_USERNAME_PASSWORD 0x02
  40. #define SOCKS_METHOD_NO_ACCEPTABLE_METHODS 0xFF
  41. #define SOCKS_CMD_CONNECT 0x01
  42. #define SOCKS_CMD_BIND 0x02
  43. #define SOCKS_CMD_UDP_ASSOCIATE 0x03
  44. #define SOCKS_ATYP_IPV4 0x01
  45. #define SOCKS_ATYP_DOMAINNAME 0x03
  46. #define SOCKS_ATYP_IPV6 0x04
  47. #define SOCKS_REP_SUCCEEDED 0x00
  48. #define SOCKS_REP_GENERAL_FAILURE 0x01
  49. #define SOCKS_REP_CONNECTION_NOT_ALLOWED 0x02
  50. #define SOCKS_REP_NETWORK_UNREACHABLE 0x03
  51. #define SOCKS_REP_HOST_UNREACHABLE 0x04
  52. #define SOCKS_REP_CONNECTION_REFUSED 0x05
  53. #define SOCKS_REP_TTL_EXPIRED 0x06
  54. #define SOCKS_REP_COMMAND_NOT_SUPPORTED 0x07
  55. #define SOCKS_REP_ADDRESS_TYPE_NOT_SUPPORTED 0x08
  56. struct socks_client_hello_header {
  57. uint8_t ver;
  58. uint8_t nmethods;
  59. } __attribute__((packed));
  60. struct socks_client_hello_method {
  61. uint8_t method;
  62. } __attribute__((packed));
  63. struct socks_server_hello {
  64. uint8_t ver;
  65. uint8_t method;
  66. } __attribute__((packed));
  67. struct socks_request_header {
  68. uint8_t ver;
  69. uint8_t cmd;
  70. uint8_t rsv;
  71. uint8_t atyp;
  72. } __attribute__((packed));
  73. struct socks_reply_header {
  74. uint8_t ver;
  75. uint8_t rep;
  76. uint8_t rsv;
  77. uint8_t atyp;
  78. } __attribute__((packed));
  79. struct socks_addr_ipv4 {
  80. uint32_t addr;
  81. uint16_t port;
  82. } __attribute__((packed));
  83. struct socks_addr_ipv6 {
  84. uint8_t addr[16];
  85. uint16_t port;
  86. } __attribute__((packed));
  87. #endif