Mercurial > hg > nginx
comparison src/core/ngx_inet.c @ 4582:a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
In collaboration with Maxim Dounin.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 11 Apr 2012 17:18:15 +0000 |
parents | 98a2518a98dc |
children | 3d51fa5a110d |
comparison
equal
deleted
inserted
replaced
4581:f84a98a03d0d | 4582:a8881886a5f7 |
---|---|
418 for (i = 0; i < 16; i++) { | 418 for (i = 0; i < 16; i++) { |
419 | 419 |
420 s = (shift > 8) ? 8 : shift; | 420 s = (shift > 8) ? 8 : shift; |
421 shift -= s; | 421 shift -= s; |
422 | 422 |
423 mask[i] = (u_char) (0 - (1 << (8 - s))); | 423 mask[i] = (u_char) (0xffu << (8 - s)); |
424 | 424 |
425 if (addr[i] != (addr[i] & mask[i])) { | 425 if (addr[i] != (addr[i] & mask[i])) { |
426 rc = NGX_DONE; | 426 rc = NGX_DONE; |
427 addr[i] &= mask[i]; | 427 addr[i] &= mask[i]; |
428 } | 428 } |
435 if (shift > 32) { | 435 if (shift > 32) { |
436 return NGX_ERROR; | 436 return NGX_ERROR; |
437 } | 437 } |
438 | 438 |
439 if (shift) { | 439 if (shift) { |
440 cidr->u.in.mask = htonl((ngx_uint_t) (0 - (1 << (32 - shift)))); | 440 cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift))); |
441 | 441 |
442 } else { | 442 } else { |
443 /* x86 compilers use a shl instruction that shifts by modulo 32 */ | 443 /* x86 compilers use a shl instruction that shifts by modulo 32 */ |
444 cidr->u.in.mask = 0; | 444 cidr->u.in.mask = 0; |
445 } | 445 } |