aboutsummaryrefslogtreecommitdiff
path: root/mctypes.c
diff options
context:
space:
mode:
authorPlex <thinkplex@riseup.net>2021-10-25 16:47:49 +0200
committerPlex <thinkplex@riseup.net>2021-10-25 16:47:49 +0200
commitd25c1b105da1606d3e372974d7546c1f7726a198 (patch)
tree357040b6be050bad2f6603419712446cf9ac2184 /mctypes.c
parent53a085962964f4db118619a5e2156c901aba55a6 (diff)
handshake serialized
Diffstat (limited to 'mctypes.c')
-rw-r--r--mctypes.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/mctypes.c b/mctypes.c
index 30319ee..79adc73 100644
--- a/mctypes.c
+++ b/mctypes.c
@@ -32,33 +32,33 @@ int readVarInt(varint x)
return (int) res;
}
-size_t serializeHandshake(handshake hs, void *buf)
+size_t serializeHandshake(handshake hs, void **buf)
{
size_t size = 0;
size_t vi_size;
- buf = malloc(size);
+ *buf = malloc(size);
for (vi_size = 1; (hs.protocol_version[vi_size - 1] & 0x80) != 0; vi_size++);
- buf = realloc(buf, size+vi_size);
- memcpy(buf + size, hs.protocol_version, vi_size);
+ *buf = realloc(*buf, size+vi_size);
+ memcpy(*buf + size, hs.protocol_version, vi_size);
size += vi_size;
for (vi_size = 1; (hs.server_address.length[vi_size - 1] & 0x80) != 0; vi_size++);
- buf = realloc(buf, size+vi_size);
- memcpy(buf + size, hs.server_address.length, vi_size);
+ *buf = realloc(*buf, size+vi_size);
+ memcpy(*buf + size, hs.server_address.length, vi_size);
size += vi_size;
- buf = realloc(buf, size+readVarInt(hs.server_address.length));
- memcpy(buf + size, hs.server_address.content, readVarInt(hs.server_address.length));
+ *buf = realloc(*buf, size+readVarInt(hs.server_address.length));
+ memcpy(*buf + size, hs.server_address.content, readVarInt(hs.server_address.length));
size += readVarInt(hs.server_address.length);
- buf = realloc(buf, size+sizeof(unsigned short));
- memcpy(buf + size, &hs.server_port, sizeof(unsigned short));
+ *buf = realloc(*buf, size+sizeof(unsigned short));
+ memcpy(*buf + size, &hs.server_port, sizeof(unsigned short));
size += sizeof(unsigned short);
for (vi_size = 1; (hs.next_state[vi_size - 1] & 0x80) != 0; vi_size++);
- buf = realloc(buf, size+vi_size);
- memcpy(buf + size, hs.next_state, vi_size);
+ *buf = realloc(*buf, size+vi_size);
+ memcpy(*buf + size, hs.next_state, vi_size);
size += vi_size;
return size;