Guest User

Untitled

a guest
Aug 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /* first calculate the prefix length */
  2. if(slash) {
  3. pfx_len = (int)strtoul(slash + 1, NULL, 10);
  4. if(!pfx_len && memcmp(in_zero, in_net, sizeof(struct in6_addr)))
  5. goto end;
  6.  
  7. /* if it's an ipv4 address (ie, the first 80 bits are zero), then
  8. * we need to add 96 to the prefix length.
  9. */
  10. if(!memcmp(in_zero, in_net, 10))
  11. pfx_len += 96;
  12.  
  13. if(pfx_len > 128 || pfx_len < 0)
  14. goto end;
  15. }
  16. else {
  17. pfx_len = 128;
  18. }
  19. /* now we need to fill the mask and then bitwise-and it properly */
  20. for(i = 0; i < 3; i++) {
  21. if(pfx_len >= 32) {
  22. mask->s6_addr32[i] = 0xffffffff;
  23. pfx_len -= 32;
  24. }
  25. else if(!pfx_len) {
  26. mask->s6_addr32[i] = 0;
  27. }
  28. else {
  29. m = 0xffffffff;
  30. m <<= 32 - pfx_len;
  31. mask->s6_addr32[i] = htonl(m);
  32. }
  33. }
Add Comment
Please, Sign In to add comment