diff options
author | Plex <thinkplex@riseup.net> | 2021-10-25 16:47:49 +0200 |
---|---|---|
committer | Plex <thinkplex@riseup.net> | 2021-10-25 16:47:49 +0200 |
commit | d25c1b105da1606d3e372974d7546c1f7726a198 (patch) | |
tree | 357040b6be050bad2f6603419712446cf9ac2184 /mctypes.c | |
parent | 53a085962964f4db118619a5e2156c901aba55a6 (diff) |
handshake serialized
Diffstat (limited to 'mctypes.c')
-rw-r--r-- | mctypes.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -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; |