diff src/core/ngx_inet.c @ 368:15c84a40e87d

nginx-0.0.7-2004-06-24-20:07:04 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 24 Jun 2004 16:07:04 +0000
parents 0bf903191ceb
children 37b5381fb6d8
line wrap: on
line diff
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -170,6 +170,7 @@ size_t ngx_inet_ntop(int family, void *a
 
 ngx_int_t ngx_ptocidr(ngx_str_t *text, void *cidr)
 {
+    ngx_int_t         m;
     ngx_uint_t        i;
     ngx_inet_cidr_t  *in_cidr;
 
@@ -192,10 +193,20 @@ ngx_int_t ngx_ptocidr(ngx_str_t *text, v
         return NGX_ERROR;
     }
 
-    in_cidr->mask = ngx_atoi(&text->data[i + 1], text->len - (i + 1));
-    if (in_cidr->mask == (in_addr_t) NGX_ERROR) {
+    m = ngx_atoi(&text->data[i + 1], text->len - (i + 1));
+    if (m == NGX_ERROR) {
         return NGX_ERROR;
     }
 
+    if (m == 0) {
+
+        /* the x86 compilers use the shl instruction that shifts by modulo 32 */
+
+        in_cidr->mask = 0;
+        return NGX_OK;
+    }
+
+    in_cidr->mask = (ngx_uint_t) (0 - (1 << (32 - m)));
+
     return NGX_OK;
 }