From 878efdc969facf85d43498d4025ca7841de8b3bc Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 14 Nov 2016 01:59:06 +0100 Subject: Convert to and from network byte order in set/get nospam. Fixes #205. --- toxcore/tox.api.h | 7 +++++-- toxcore/tox.c | 4 ++-- toxcore/tox.h | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'toxcore') diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 2df57429..e9e3483d 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h @@ -844,14 +844,17 @@ inline namespace self { uint32_t nospam { /** - * Set the 4-byte nospam part of the address. + * Set the 4-byte nospam part of the address. This value is expected in host + * byte order. I.e. 0x12345678 will form the bytes [12, 34, 56, 78] in the + * nospam part of the Tox friend address. * * @param nospam Any 32 bit unsigned integer. */ set(); /** - * Get the 4-byte nospam part of the address. + * Get the 4-byte nospam part of the address. This value is returned in host + * byte order. */ get(); } diff --git a/toxcore/tox.c b/toxcore/tox.c index 7898868b..c7d90871 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -479,13 +479,13 @@ void tox_self_get_address(const Tox *tox, uint8_t *address) void tox_self_set_nospam(Tox *tox, uint32_t nospam) { Messenger *m = tox; - set_nospam(&(m->fr), nospam); + set_nospam(&(m->fr), htonl(nospam)); } uint32_t tox_self_get_nospam(const Tox *tox) { const Messenger *m = tox; - return get_nospam(&(m->fr)); + return ntohl(get_nospam(&(m->fr))); } void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) diff --git a/toxcore/tox.h b/toxcore/tox.h index eae37ac2..af25d8fa 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -979,14 +979,17 @@ void tox_iterate(Tox *tox, void *user_data); void tox_self_get_address(const Tox *tox, uint8_t *address); /** - * Set the 4-byte nospam part of the address. + * Set the 4-byte nospam part of the address. This value is expected in host + * byte order. I.e. 0x12345678 will form the bytes [12, 34, 56, 78] in the + * nospam part of the Tox friend address. * * @param nospam Any 32 bit unsigned integer. */ void tox_self_set_nospam(Tox *tox, uint32_t nospam); /** - * Get the 4-byte nospam part of the address. + * Get the 4-byte nospam part of the address. This value is returned in host + * byte order. */ uint32_t tox_self_get_nospam(const Tox *tox); -- cgit v1.2.3