diff options
author | Plex <thinkplex@riseup.net> | 2021-10-25 18:41:59 +0200 |
---|---|---|
committer | Plex <thinkplex@riseup.net> | 2021-10-25 18:41:59 +0200 |
commit | d23f7f0aaa97103670e229abd402ad66a6e703de (patch) | |
tree | 29a252121af2bb3a93f2ad0b28e0160687b31601 /mctypes.c | |
parent | 927c5b7219041a353010141cea139642ac6ca0bf (diff) |
refactoring !!
Diffstat (limited to 'mctypes.c')
-rw-r--r-- | mctypes.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -1,8 +1,6 @@ #include "mctypes.h" #include <stdlib.h> #include <string.h> -#include <sys/socket.h> - varint to_varint(unsigned int x) { @@ -33,7 +31,7 @@ int from_varint(varint x) return (int) res; } -size_t len_varint(varint x) +size_t size_varint(varint x) { size_t v_size; for (v_size = 1; (x[v_size - 1] & 0x80) != 0; v_size++); @@ -46,12 +44,12 @@ size_t serialize_handshake(handshake hs, void **buf) size_t varint_s; *buf = malloc(size); - varint_s = len_varint(hs.protocol_version); + varint_s = size_varint(hs.protocol_version); *buf = realloc(*buf, size+varint_s); memcpy(*buf + size, hs.protocol_version, varint_s); size += varint_s; - varint_s = len_varint(hs.server_address.length); + varint_s = size_varint(hs.server_address.length); *buf = realloc(*buf, size+varint_s); memcpy(*buf + size, hs.server_address.length, varint_s); size += varint_s; @@ -64,7 +62,7 @@ size_t serialize_handshake(handshake hs, void **buf) memcpy(*buf + size, &hs.server_port, sizeof(unsigned short)); size += sizeof(unsigned short); - varint_s = len_varint(hs.next_state); + varint_s = size_varint(hs.next_state); *buf = realloc(*buf, size+varint_s); memcpy(*buf + size, hs.next_state, varint_s); size += varint_s; @@ -74,7 +72,7 @@ size_t serialize_handshake(handshake hs, void **buf) size_t serialize_packet(packet p, void **buf) { - size_t v_size = len_varint(p.length); + size_t v_size = size_varint(p.length); size_t p_size = from_varint(p.length) + v_size; // total size of packet size_t size = 0; |