Convert to and from network byte order in set/get nospam.

Fixes #205.
This commit is contained in:
iphydf 2016-11-14 01:59:06 +01:00
parent 8822f595a8
commit 878efdc969
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
3 changed files with 12 additions and 6 deletions

View File

@ -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();
}

View File

@ -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)

View File

@ -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);