socks5.trunnel 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Example: here's a quickie implementation of the messages in the
  2. // socks5 protocol.
  3. struct socks5_client_version {
  4. u8 version IN [5];
  5. u8 n_methods;
  6. u8 methods[n_methods];
  7. }
  8. struct socks5_server_method {
  9. u8 version IN [5];
  10. u8 method;
  11. }
  12. const CMD_CONNECT = 1;
  13. const CMD_BIND = 2;
  14. const CMD_UDP_ASSOCIATE = 3;
  15. // This is a tor extension
  16. const CMD_RESOLVE_PTR = 0xF1;
  17. const ATYPE_IPV4 = 1;
  18. const ATYPE_IPV6 = 4;
  19. const ATYPE_DOMAINNAME = 3;
  20. struct domainname {
  21. u8 len;
  22. char name[len];
  23. }
  24. struct socks5_client_request {
  25. u8 version IN [5];
  26. u8 command IN [CMD_CONNECT, CMD_BIND, CMD_UDP_ASSOCIATE, CMD_RESOLVE_PTR];
  27. u8 reserved IN [0];
  28. u8 atype;
  29. union dest_addr[atype] {
  30. ATYPE_IPV4: u32 ipv4;
  31. ATYPE_IPV6: u8 ipv6[16];
  32. ATYPE_DOMAINNAME: struct domainname domainname;
  33. default: fail;
  34. };
  35. u16 dest_port;
  36. }
  37. struct socks5_server_reply {
  38. u8 version IN [5];
  39. u8 reply;
  40. u8 reserved IN [0];
  41. u8 atype;
  42. union bind_addr[atype] {
  43. ATYPE_IPV4: u32 ipv4;
  44. ATYPE_IPV6: u8 ipv6[16];
  45. ATYPE_DOMAINNAME: struct domainname domainname;
  46. default: fail;
  47. };
  48. u16 bind_port;
  49. }
  50. struct socks5_client_userpass_auth {
  51. u8 version IN [1];
  52. u8 username_len;
  53. char username[username_len];
  54. u8 passwd_len;
  55. char passwd[passwd_len];
  56. }
  57. struct socks5_server_userpath_auth {
  58. u8 version IN [1];
  59. u8 status;
  60. }
  61. // Oh why not. Here's socks4 and socks4a.
  62. struct socks4_client_request {
  63. u8 version IN [4];
  64. u8 command IN [CMD_CONNECT,CMD_BIND,CMD_RESOLVE_PTR];
  65. u16 port;
  66. u32 addr;
  67. nulterm username;
  68. union socks4a_addr[addr] {
  69. 1..255:
  70. nulterm hostname;
  71. default:
  72. ;
  73. };
  74. }
  75. struct socks4_server_reply {
  76. u8 version IN [4];
  77. u8 status;
  78. u16 port;
  79. u32 addr;
  80. }
  81. // And here's the extended stuff from proposal 229
  82. struct tor_socksauth_keyval {
  83. u16 keylen;
  84. char key[keylen];
  85. u16 vallen;
  86. char val[vallen];
  87. }
  88. struct tor_extended_socks_auth_request {
  89. u8 version IN [1];
  90. u16 npairs;
  91. struct tor_socksauth_keyval pairs[npairs];
  92. }
  93. struct tor_extended_socks_auth_response {
  94. u8 version IN [1];
  95. u8 status;
  96. u16 npairs;
  97. struct tor_socksauth_keyval pairs[npairs];
  98. }