summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-11-14 01:59:06 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-11-15 17:56:21 +0000
commit878efdc969facf85d43498d4025ca7841de8b3bc (patch)
treeb9a7fe3b7a0db3a887899600e573b1c57a96cee6 /toxcore
parent8822f595a8eaa3eb20195c967642445377aa3881 (diff)
Convert to and from network byte order in set/get nospam.
Fixes #205.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/tox.api.h7
-rw-r--r--toxcore/tox.c4
-rw-r--r--toxcore/tox.h7
3 files changed, 12 insertions, 6 deletions
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 {
844 844
845 uint32_t nospam { 845 uint32_t nospam {
846 /** 846 /**
847 * Set the 4-byte nospam part of the address. 847 * Set the 4-byte nospam part of the address. This value is expected in host
848 * byte order. I.e. 0x12345678 will form the bytes [12, 34, 56, 78] in the
849 * nospam part of the Tox friend address.
848 * 850 *
849 * @param nospam Any 32 bit unsigned integer. 851 * @param nospam Any 32 bit unsigned integer.
850 */ 852 */
851 set(); 853 set();
852 854
853 /** 855 /**
854 * Get the 4-byte nospam part of the address. 856 * Get the 4-byte nospam part of the address. This value is returned in host
857 * byte order.
855 */ 858 */
856 get(); 859 get();
857 } 860 }
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)
479void tox_self_set_nospam(Tox *tox, uint32_t nospam) 479void tox_self_set_nospam(Tox *tox, uint32_t nospam)
480{ 480{
481 Messenger *m = tox; 481 Messenger *m = tox;
482 set_nospam(&(m->fr), nospam); 482 set_nospam(&(m->fr), htonl(nospam));
483} 483}
484 484
485uint32_t tox_self_get_nospam(const Tox *tox) 485uint32_t tox_self_get_nospam(const Tox *tox)
486{ 486{
487 const Messenger *m = tox; 487 const Messenger *m = tox;
488 return get_nospam(&(m->fr)); 488 return ntohl(get_nospam(&(m->fr)));
489} 489}
490 490
491void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) 491void 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);
979void tox_self_get_address(const Tox *tox, uint8_t *address); 979void tox_self_get_address(const Tox *tox, uint8_t *address);
980 980
981/** 981/**
982 * Set the 4-byte nospam part of the address. 982 * Set the 4-byte nospam part of the address. This value is expected in host
983 * byte order. I.e. 0x12345678 will form the bytes [12, 34, 56, 78] in the
984 * nospam part of the Tox friend address.
983 * 985 *
984 * @param nospam Any 32 bit unsigned integer. 986 * @param nospam Any 32 bit unsigned integer.
985 */ 987 */
986void tox_self_set_nospam(Tox *tox, uint32_t nospam); 988void tox_self_set_nospam(Tox *tox, uint32_t nospam);
987 989
988/** 990/**
989 * Get the 4-byte nospam part of the address. 991 * Get the 4-byte nospam part of the address. This value is returned in host
992 * byte order.
990 */ 993 */
991uint32_t tox_self_get_nospam(const Tox *tox); 994uint32_t tox_self_get_nospam(const Tox *tox);
992 995