socks_proto.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file socks_proto.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. * Definitions for the SOCKS protocol.
  25. */
  26. #ifndef BADVPN_MISC_SOCKS_PROTO_H
  27. #define BADVPN_MISC_SOCKS_PROTO_H
  28. #include <stdint.h>
  29. #define SOCKS_VERSION 0x05
  30. #define SOCKS_METHOD_NO_AUTHENTICATION_REQUIRED 0x00
  31. #define SOCKS_METHOD_GSSAPI 0x01
  32. #define SOCKS_METHOD_USERNAME_PASSWORD 0x02
  33. #define SOCKS_METHOD_NO_ACCEPTABLE_METHODS 0xFF
  34. #define SOCKS_CMD_CONNECT 0x01
  35. #define SOCKS_CMD_BIND 0x02
  36. #define SOCKS_CMD_UDP_ASSOCIATE 0x03
  37. #define SOCKS_ATYP_IPV4 0x01
  38. #define SOCKS_ATYP_DOMAINNAME 0x03
  39. #define SOCKS_ATYP_IPV6 0x04
  40. #define SOCKS_REP_SUCCEEDED 0x00
  41. #define SOCKS_REP_GENERAL_FAILURE 0x01
  42. #define SOCKS_REP_CONNECTION_NOT_ALLOWED 0x02
  43. #define SOCKS_REP_NETWORK_UNREACHABLE 0x03
  44. #define SOCKS_REP_HOST_UNREACHABLE 0x04
  45. #define SOCKS_REP_CONNECTION_REFUSED 0x05
  46. #define SOCKS_REP_TTL_EXPIRED 0x06
  47. #define SOCKS_REP_COMMAND_NOT_SUPPORTED 0x07
  48. #define SOCKS_REP_ADDRESS_TYPE_NOT_SUPPORTED 0x08
  49. struct socks_client_hello_header {
  50. uint8_t ver;
  51. uint8_t nmethods;
  52. } __attribute__((packed));
  53. struct socks_client_hello_method {
  54. uint8_t method;
  55. } __attribute__((packed));
  56. struct socks_server_hello {
  57. uint8_t ver;
  58. uint8_t method;
  59. } __attribute__((packed));
  60. struct socks_request_header {
  61. uint8_t ver;
  62. uint8_t cmd;
  63. uint8_t rsv;
  64. uint8_t atyp;
  65. } __attribute__((packed));
  66. struct socks_reply_header {
  67. uint8_t ver;
  68. uint8_t rep;
  69. uint8_t rsv;
  70. uint8_t atyp;
  71. } __attribute__((packed));
  72. struct socks_addr_ipv4 {
  73. uint32_t addr;
  74. uint16_t port;
  75. } __attribute__((packed));
  76. struct socks_addr_ipv6 {
  77. uint8_t addr[16];
  78. uint16_t port;
  79. } __attribute__((packed));
  80. #endif