diff options
author | Steven Barth <steven@midlink.org> | 2014-02-17 21:08:29 +0100 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2014-02-17 21:08:29 +0100 |
commit | e9a21fdb43c9f94762a724db1a043b376f745ae3 (patch) | |
tree | 46704261aec9ca25023541c0d7275db2ebaf71be /src/odhcpd.c | |
parent | 6d644f0991c51fffcc5312e73b42126b7c6559bf (diff) |
Add support for (managed) prefixes of length 65-96
Diffstat (limited to 'src/odhcpd.c')
-rw-r--r-- | src/odhcpd.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/odhcpd.c b/src/odhcpd.c index f40cea0..25a6047 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -427,3 +427,33 @@ void odhcpd_hexlify(char *dst, const uint8_t *src, size_t len) } *dst = 0; } + + +int odhcpd_bmemcmp(const void *av, const void *bv, size_t bits) +{ + const uint8_t *a = av, *b = bv; + size_t bytes = bits / 8; + bits %= 8; + + int res = memcmp(a, b, bytes); + if (res == 0 && bits > 0) + res = (a[bytes] >> (8 - bits)) - (b[bytes] >> (8 - bits)); + + return res; +} + + +void odhcpd_bmemcpy(void *av, const void *bv, size_t bits) +{ + uint8_t *a = av; + const uint8_t *b = bv; + + size_t bytes = bits / 8; + bits %= 8; + memcpy(a, b, bytes); + + if (bits > 0) { + uint8_t mask = (1 << (8 - bits)) - 1; + a[bytes] = (a[bytes] & mask) | ((~mask) & b[bytes]); + } +} |