diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-08-06 21:32:01 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-08-06 21:32:01 +0200 |
commit | c8890953b321ad8604051b22e1f3bf91d9ff4b15 (patch) | |
tree | 319fc118a1a74386b91c0d3106a6369b1e80425d /common.c | |
parent | cfc78ffdf06d96c43272ba42cecf75f00126d2a5 (diff) | |
download | xK-c8890953b321ad8604051b22e1f3bf91d9ff4b15.tar.gz xK-c8890953b321ad8604051b22e1f3bf91d9ff4b15.tar.xz xK-c8890953b321ad8604051b22e1f3bf91d9ff4b15.zip |
SOCKS: make use of the str_pack_* API
I forgot I had it.
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -516,12 +516,11 @@ socks_4a_start (struct socks_connector *self) struct str *wb = &self->write_buffer; str_init (wb); - str_append_c (wb, 4); // version - str_append_c (wb, 1); // connect + str_pack_u8 (wb, 4); // version + str_pack_u8 (wb, 1); // connect - str_append_c (wb, target->port >> 8); // higher bits of port - str_append_c (wb, target->port); // lower bits of port - str_append_data (wb, dest_ipv4, 4); // destination address + str_pack_u16 (wb, target->port); // port + str_append_data (wb, dest_ipv4, 4); // destination address if (self->username) str_append (wb, self->username); @@ -613,10 +612,10 @@ socks_5_request_start (struct socks_connector *self) { struct socks_target *target = self->targets_iter; struct str *wb = &self->write_buffer; - str_append_c (wb, 0x05); // version - str_append_c (wb, 0x01); // connect - str_append_c (wb, 0x00); // reserved - str_append_c (wb, target->address.type); + str_pack_u8 (wb, 0x05); // version + str_pack_u8 (wb, 0x01); // connect + str_pack_u8 (wb, 0x00); // reserved + str_pack_u8 (wb, target->address.type); switch (target->address.type) { @@ -630,7 +629,7 @@ socks_5_request_start (struct socks_connector *self) if (dlen > 255) dlen = 255; - str_append_c (wb, dlen); + str_pack_u8 (wb, dlen); str_append_data (wb, target->address.data.domain, dlen); break; } @@ -639,8 +638,7 @@ socks_5_request_start (struct socks_connector *self) target->address.data.ipv6, sizeof target->address.data.ipv6); break; } - str_append_c (wb, target->port >> 8); - str_append_c (wb, target->port); + str_pack_u16 (wb, target->port); SOCKS_GO (socks_5_request_finish, 4); } @@ -673,10 +671,10 @@ socks_5_userpass_start (struct socks_connector *self) plen = 255; struct str *wb = &self->write_buffer; - str_append_c (wb, 0x01); // version - str_append_c (wb, ulen); // username length + str_pack_u8 (wb, 0x01); // version + str_pack_u8 (wb, ulen); // username length str_append_data (wb, self->username, ulen); - str_append_c (wb, plen); // password length + str_pack_u8 (wb, plen); // password length str_append_data (wb, self->password, plen); SOCKS_GO (socks_5_userpass_finish, 2); @@ -715,11 +713,11 @@ socks_5_auth_start (struct socks_connector *self) bool can_auth = self->username && self->password; struct str *wb = &self->write_buffer; - str_append_c (wb, 0x05); // version - str_append_c (wb, 1 + can_auth); // number of authentication methods - str_append_c (wb, 0x00); // no authentication required + str_pack_u8 (wb, 0x05); // version + str_pack_u8 (wb, 1 + can_auth); // number of authentication methods + str_pack_u8 (wb, 0x00); // no authentication required if (can_auth) - str_append_c (wb, 0x02); // username/password + str_pack_u8 (wb, 0x02); // username/password SOCKS_GO (socks_5_auth_finish, 2); } |