Commit 3bd27449 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix mask_prefix.

parent e697c912
......@@ -154,17 +154,16 @@ in_prefix(const unsigned char *address,
}
const unsigned char *
mask_prefix(const unsigned char *prefix, unsigned char plen)
mask_prefix(unsigned char *ret,
const unsigned char *prefix, unsigned char plen)
{
static unsigned char ret[16];
if(plen > 128)
plen = 128;
memset(ret, 0, 16);
memcpy(ret, prefix, plen / 8);
if(plen % 8 != 0)
ret[plen / 8] = 0xFF << (8 - (plen % 8));
ret[plen / 8] = (prefix[plen / 8] & (0xFF << (8 - (plen % 8))));
return (const unsigned char *)ret;
}
......@@ -236,7 +235,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
return -1;
}
}
memcpy(prefix_r, mask_prefix(prefix, plen), 16);
mask_prefix(prefix_r, prefix, plen);
*plen_r = plen;
return 0;
}
......
......@@ -38,7 +38,8 @@ void do_debugf(const char *format, ...) ATTRIBUTE ((format (printf, 1, 2)));
int in_prefix(const unsigned char *address,
const unsigned char *prefix, unsigned char plen)
ATTRIBUTE ((pure));
const unsigned char *mask_prefix(const unsigned char *prefix,
const 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);
......
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