nginx-quic/src/core/ngx_inet.c

37 lines
869 B
C
Raw Normal View History

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