Commit 324bfb30 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify mask_prefix.

parent 35c4c802
......@@ -222,18 +222,20 @@ in_prefix(const unsigned char *address,
return ((address[plen / 8] & m) == (prefix[plen / 8] & m));
}
const unsigned char *
unsigned char *
mask_prefix(unsigned char *ret,
const unsigned char *prefix, unsigned char plen)
{
if(plen > 128)
plen = 128;
if(plen >= 128) {
memcpy(ret, prefix, 16);
return ret;
}
memset(ret, 0, 16);
memcpy(ret, prefix, plen / 8);
if(plen % 8 != 0)
ret[plen / 8] = (prefix[plen / 8] & (0xFF << (8 - (plen % 8))));
return (const unsigned char *)ret;
return ret;
}
static const unsigned char v4prefix[16] =
......
......@@ -60,9 +60,8 @@ void do_debugf(int leve, const char *format, ...)
int in_prefix(const unsigned char *address,
const unsigned char *prefix, unsigned char plen)
ATTRIBUTE ((pure));
const unsigned char *mask_prefix(unsigned char *ret,
const unsigned char *prefix,
unsigned char plen);
unsigned char *mask_prefix(unsigned char *ret,
const unsigned char *prefix, unsigned char plen);
const char *format_address(const unsigned char *address);
const char *format_prefix(const unsigned char *address, unsigned char prefix);
const char * format_eui64(const unsigned char *eui);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment