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