comparison src/core/ngx_inet.c @ 340:0bf903191ceb

nginx-0.0.3-2004-05-25-19:28:46 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 25 May 2004 15:28:46 +0000
parents 117ccc7c4055
children 15c84a40e87d
comparison
equal deleted inserted replaced
339:8c5b69141dfd 340:0bf903191ceb
162 return ngx_snprintf((char *) text, 162 return ngx_snprintf((char *) text,
163 len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len, 163 len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
164 "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); 164 "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
165 #endif 165 #endif
166 } 166 }
167
168
169 /* AF_INET only */
170
171 ngx_int_t ngx_ptocidr(ngx_str_t *text, void *cidr)
172 {
173 ngx_uint_t i;
174 ngx_inet_cidr_t *in_cidr;
175
176 in_cidr = cidr;
177
178 for (i = 0; i < text->len; i++) {
179 if (text->data[i] == '/') {
180 break;
181 }
182 }
183
184 if (i == text->len) {
185 return NGX_ERROR;
186 }
187
188 text->data[i] = '\0';
189 in_cidr->addr = inet_addr((char *) text->data);
190 text->data[i] = '/';
191 if (in_cidr->addr == INADDR_NONE) {
192 return NGX_ERROR;
193 }
194
195 in_cidr->mask = ngx_atoi(&text->data[i + 1], text->len - (i + 1));
196 if (in_cidr->mask == (in_addr_t) NGX_ERROR) {
197 return NGX_ERROR;
198 }
199
200 return NGX_OK;
201 }