mirror of
https://github.com/nginx/nginx.git
synced 2025-01-08 23:23:02 -06:00
ngx_inet_addr()
This commit is contained in:
parent
48bf997e10
commit
36b634cdbc
@ -8,6 +8,51 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
/* AF_INET only */
|
||||
|
||||
in_addr_t
|
||||
ngx_inet_addr(u_char *text, size_t len)
|
||||
{
|
||||
u_char *p, c;
|
||||
in_addr_t addr;
|
||||
ngx_uint_t octet, n;
|
||||
|
||||
addr = 0;
|
||||
octet = 0;
|
||||
n = 0;
|
||||
|
||||
for (p = text; p < text + len; p++) {
|
||||
|
||||
c = *p;
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
octet = octet * 10 + (c - '0');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '.' && octet < 256) {
|
||||
addr = (addr << 8) + octet;
|
||||
octet = 0;
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
if (n != 3) {
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
if (octet < 256) {
|
||||
addr = (addr << 8) + octet;
|
||||
return htonl(addr);
|
||||
}
|
||||
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ngx_sock_ntop() and ngx_inet_ntop() may be implemented as
|
||||
* "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", however,
|
||||
|
@ -58,6 +58,7 @@ typedef struct {
|
||||
} ngx_url_t;
|
||||
|
||||
|
||||
in_addr_t ngx_inet_addr(u_char *text, size_t len);
|
||||
size_t ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, size_t len);
|
||||
size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len);
|
||||
ngx_int_t ngx_ptocidr(ngx_str_t *text, void *cidr);
|
||||
|
Loading…
Reference in New Issue
Block a user