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 | |
parent | 53a085962964f4db118619a5e2156c901aba55a6 (diff) |
handshake serialized
-rwxr-xr-x | mcping | bin | 21816 -> 21856 bytes | |||
-rw-r--r-- | mcping.c | 6 | ||||
-rw-r--r-- | mctypes.c | 24 | ||||
-rw-r--r-- | mctypes.h | 2 |
4 files changed, 16 insertions, 16 deletions
Binary files differ @@ -73,12 +73,12 @@ int main(int argc, char *argv[]) writeVarInt(1) }; - char u; - char* raw_hs = &u; - size_t hs_size = serializeHandshake(hs, raw_hs); + unsigned char *raw_hs; + size_t hs_size = serializeHandshake(hs, &raw_hs); printf("%lu\n", hs_size); for (int i = 0; i < hs_size; ++i) { printf("%02X ", raw_hs[i]); } + printf("\n"); return 0; } @@ -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; @@ -26,5 +26,5 @@ typedef long pong; int readVarInt(varint x); varint writeVarInt(unsigned int x); -size_t serializeHandshake(handshake hs, void *buf); +size_t serializeHandshake(handshake hs, void **buf); size_t serializePacket(packet p, void *buf); |