socks5.trunnel 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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, 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. }