summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/common.c b/common.c
index fdf0db6..8ce16c4 100644
--- a/common.c
+++ b/common.c
@@ -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);
}