diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-04 18:11:21 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-04 18:13:57 +0200 |
commit | 536a98c12f37e6b1afaad2379ada7ab3e3b9af38 (patch) | |
tree | d135d68592616dc7ea70fb143a5b8e76c751df4f | |
parent | allowedips: use native endian on lookup (diff) | |
download | wireguard-monolithic-historical-jd/endianness-trick.tar.xz wireguard-monolithic-historical-jd/endianness-trick.zip |
allowedips: single expression endian choicejd/endianness-trick
This will upset millions of curious onlookers, and people will begin to
doubt my judgement and sanity. But this really is cleaner to express as
a single statement.
-rw-r--r-- | src/allowedips.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/allowedips.c b/src/allowedips.c index c1d9bb8..0f1fed2 100644 --- a/src/allowedips.c +++ b/src/allowedips.c @@ -31,10 +31,7 @@ static __always_inline void swap_endian(u8 *dst, const u8 *src, u8 bits) static void copy_and_assign_cidr(struct allowedips_node *node, const u8 *src, u8 cidr, u8 bits) { node->cidr = cidr; - node->bit_at_a = cidr / 8; -#ifdef __LITTLE_ENDIAN - node->bit_at_a ^= (bits / 8 - 1) % 8; -#endif + node->bit_at_a = (cidr / 8) ^ (((bits / 8 - 1) % 8) * *(u8 *)((u16 []){ 1 })); node->bit_at_b = 7 - (cidr % 8); memcpy(node->bits, src, bits / 8); } |