2002-12-15 14:25:09 +08:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
2003-06-03 23:42:58 +08:00
|
|
|
#include <ngx_core.h>
|
2002-12-15 14:25:09 +08:00
|
|
|
|
|
|
|
|
2003-01-30 15:28:09 +08:00
|
|
|
/* AF_INET only */
|
|
|
|
|
|
|
|
size_t ngx_sock_ntop(int family, struct sockaddr *addr, char *text, size_t len)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
struct sockaddr_in *addr_in;
|
|
|
|
|
|
|
|
if (family != AF_INET) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_in = (struct sockaddr_in *) addr;
|
|
|
|
p = (char *) &addr_in->sin_addr;
|
|
|
|
|
|
|
|
return ngx_snprintf(text, len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
|
|
|
|
"%u.%u.%u.%u",
|
|
|
|
(unsigned char) p[0],
|
|
|
|
(unsigned char) p[1],
|
|
|
|
(unsigned char) p[2],
|
|
|
|
(unsigned char) p[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
size_t ngx_inet_ntop(int family, char *addr, char *text, size_t len)
|
|
|
|
{
|
2003-01-30 15:28:09 +08:00
|
|
|
if (family != AF_INET) {
|
2002-12-15 14:25:09 +08:00
|
|
|
return 0;
|
2003-01-30 15:28:09 +08:00
|
|
|
}
|
2002-12-15 14:25:09 +08:00
|
|
|
|
|
|
|
return ngx_snprintf(text, len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
|
|
|
|
"%u.%u.%u.%u",
|
|
|
|
(unsigned char) addr[0],
|
|
|
|
(unsigned char) addr[1],
|
|
|
|
(unsigned char) addr[2],
|
|
|
|
(unsigned char) addr[3]);
|
|
|
|
}
|