socks5.trunnel 2.2 KB

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