Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* first calculate the prefix length */
- if(slash) {
- pfx_len = (int)strtoul(slash + 1, NULL, 10);
- if(!pfx_len && memcmp(in_zero, in_net, sizeof(struct in6_addr)))
- goto end;
- /* if it's an ipv4 address (ie, the first 80 bits are zero), then
- * we need to add 96 to the prefix length.
- */
- if(!memcmp(in_zero, in_net, 10))
- pfx_len += 96;
- if(pfx_len > 128 || pfx_len < 0)
- goto end;
- }
- else {
- pfx_len = 128;
- }
- /* now we need to fill the mask and then bitwise-and it properly */
- for(i = 0; i < 3; i++) {
- if(pfx_len >= 32) {
- mask->s6_addr32[i] = 0xffffffff;
- pfx_len -= 32;
- }
- else if(!pfx_len) {
- mask->s6_addr32[i] = 0;
- }
- else {
- m = 0xffffffff;
- m <<= 32 - pfx_len;
- mask->s6_addr32[i] = htonl(m);
- }
- }
Add Comment
Please, Sign In to add comment