diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-21 22:38:08 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-02-01 23:35:44 +0000 |
commit | 83779a21eaf19bbf6aa5d61d8f59681a306e4f65 (patch) | |
tree | b713524d8ce29ca05500fb95f315de94a4d4ae75 /toxcore/network.c | |
parent | d9413d557696e3aecde9d019e1738e99882d4579 (diff) |
Manually serialise RTPHeader struct instead of memcpy.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 63784475..06a875cc 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -1474,3 +1474,50 @@ uint16_t net_ntohs(uint16_t hostshort) | |||
1474 | { | 1474 | { |
1475 | return ntohs(hostshort); | 1475 | return ntohs(hostshort); |
1476 | } | 1476 | } |
1477 | |||
1478 | size_t net_pack_u16(uint8_t *bytes, uint16_t v) | ||
1479 | { | ||
1480 | bytes[0] = (v >> 8) & 0xff; | ||
1481 | bytes[1] = v & 0xff; | ||
1482 | return sizeof(v); | ||
1483 | } | ||
1484 | |||
1485 | size_t net_pack_u32(uint8_t *bytes, uint32_t v) | ||
1486 | { | ||
1487 | bytes += net_pack_u16(bytes, (v >> 16) & 0xffff); | ||
1488 | bytes += net_pack_u16(bytes, v & 0xffff); | ||
1489 | return sizeof(v); | ||
1490 | } | ||
1491 | |||
1492 | size_t net_pack_u64(uint8_t *bytes, uint64_t v) | ||
1493 | { | ||
1494 | bytes += net_pack_u32(bytes, (v >> 32) & 0xffffffff); | ||
1495 | bytes += net_pack_u32(bytes, v & 0xffffffff); | ||
1496 | return sizeof(v); | ||
1497 | } | ||
1498 | |||
1499 | size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v) | ||
1500 | { | ||
1501 | uint8_t hi = bytes[0]; | ||
1502 | uint8_t lo = bytes[1]; | ||
1503 | *v = ((uint16_t)hi << 8) | lo; | ||
1504 | return sizeof(*v); | ||
1505 | } | ||
1506 | |||
1507 | size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) | ||
1508 | { | ||
1509 | uint16_t lo, hi; | ||
1510 | bytes += net_unpack_u16(bytes, &hi); | ||
1511 | bytes += net_unpack_u16(bytes, &lo); | ||
1512 | *v = ((uint32_t)hi << 16) | lo; | ||
1513 | return sizeof(*v); | ||
1514 | } | ||
1515 | |||
1516 | size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v) | ||
1517 | { | ||
1518 | uint32_t lo, hi; | ||
1519 | bytes += net_unpack_u32(bytes, &hi); | ||
1520 | bytes += net_unpack_u32(bytes, &lo); | ||
1521 | *v = ((uint64_t)hi << 32) | lo; | ||
1522 | return sizeof(*v); | ||
1523 | } | ||