20 #if defined(LIBC_SCCS) && !defined(lint)
21 static const char rcsid[] =
"Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 marka Exp $";
42 #define PGSQL_AF_INET (AF_INET + 0)
43 #define PGSQL_AF_INET6 (AF_INET + 1)
47 #define NS_IN6ADDRSZ 16
51 #define SPRINTF(x) strlen(sprintfx)
53 #define SPRINTF(x) ((size_t)sprintf x)
57 char *dst,
size_t size);
59 char *dst,
size_t size);
90 #if AF_INET6 != PGSQL_AF_INET6
121 if (bits < 0 || bits > 32)
130 if (
size <=
sizeof ".255")
135 dst +=
SPRINTF((dst,
"%u", *src++));
136 size -= (size_t) (dst - t);
142 if (
size <=
sizeof "/32")
144 dst +=
SPRINTF((dst,
"/%u", bits));
161 for (
b = 1;
b <= bytes;
b++)
163 if (
size <=
sizeof "255.")
166 dst +=
SPRINTF((dst,
"%u", *src++));
172 size -= (size_t) (dst - t);
187 char tmp[
sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255/128"];
197 if ((bits < -1) || (bits > 128))
207 memset(words,
'\0',
sizeof words);
209 words[
i / 2] |= (src[
i] << ((1 - (
i % 2)) << 3));
227 if (best.base == -1 ||
cur.len > best.len)
235 if (best.base == -1 ||
cur.len > best.len)
238 if (best.base != -1 && best.len < 2)
248 if (best.base != -1 &&
i >= best.base &&
249 i < (best.base + best.len))
259 if (
i == 6 && best.base == 0 && (best.len == 6 ||
260 (best.len == 7 && words[7] != 0x0001) ||
261 (best.len == 5 && words[5] == 0xffff)))
265 n =
decoct(src + 12, 4, tp,
sizeof tmp - (tp - tmp));
274 tp +=
SPRINTF((tp,
"%x", words[
i]));
278 if (best.base != -1 && (best.base + best.len) ==
283 if (bits != -1 && bits != 128)
284 tp +=
SPRINTF((tp,
"/%u", bits));
289 if ((
size_t) (tp - tmp) >
size)
static char * inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
char * pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
static char * inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
static int decoct(const u_char *src, int bytes, char *dst, size_t size)
static pg_noinline void Size size