Go to the source code of this file.
|
static char * | inet_cidr_ntop_ipv4 (const u_char *src, int bits, char *dst, size_t size) |
|
static char * | inet_cidr_ntop_ipv6 (const u_char *src, int bits, char *dst, size_t size) |
|
char * | pg_inet_cidr_ntop (int af, const void *src, int bits, char *dst, size_t size) |
|
◆ SPRINTF
◆ inet_cidr_ntop_ipv4()
static char * inet_cidr_ntop_ipv4 |
( |
const u_char * |
src, |
|
|
int |
bits, |
|
|
char * |
dst, |
|
|
size_t |
size |
|
) |
| |
|
static |
Definition at line 85 of file inet_cidr_ntop.c.
92 if (bits < 0 || bits > 32)
100 if (
size <
sizeof "0")
108 for (
b = bits / 8;
b > 0;
b--)
110 if (
size <=
sizeof "255.")
113 dst +=
SPRINTF((dst,
"%u", *src++));
119 size -= (size_t) (dst - t);
126 if (
size <=
sizeof ".255")
131 m = ((1 <<
b) - 1) << (8 -
b);
132 dst +=
SPRINTF((dst,
"%u", *src & m));
133 size -= (size_t) (dst - t);
137 if (
size <=
sizeof "/32")
139 dst +=
SPRINTF((dst,
"/%u", bits));
static pg_noinline void Size size
References b, EMSGSIZE, size, and SPRINTF.
Referenced by pg_inet_cidr_ntop().
◆ inet_cidr_ntop_ipv6()
static char * inet_cidr_ntop_ipv6 |
( |
const u_char * |
src, |
|
|
int |
bits, |
|
|
char * |
dst, |
|
|
size_t |
size |
|
) |
| |
|
static |
Definition at line 165 of file inet_cidr_ntop.c.
176 unsigned char inbuf[16];
177 char outbuf[
sizeof(
"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
182 if (bits < 0 || bits > 128)
200 memcpy(inbuf, src, p);
201 memset(inbuf + p, 0, 16 - p);
205 m = ((u_int) ~0) << (8 -
b);
212 words = (bits + 15) / 16;
217 zero_s = zero_l = tmp_zero_s = tmp_zero_l = 0;
218 for (
i = 0;
i < (words * 2);
i += 2)
220 if ((s[
i] | s[
i + 1]) == 0)
228 if (tmp_zero_l && zero_l < tmp_zero_l)
237 if (tmp_zero_l && zero_l < tmp_zero_l)
243 if (zero_l != words && zero_s == 0 && ((zero_l == 6) ||
244 ((zero_l == 5 && s[10] == 0xff && s[11] == 0xff) ||
245 ((zero_l == 7 && s[14] != 0 && s[15] != 1)))))
249 for (p = 0; p < words; p++)
251 if (zero_l != 0 && p >= zero_s && p < zero_s + zero_l)
263 if (is_ipv4 && p > 5)
265 *cp++ = (p == 6) ?
':' :
'.';
266 cp +=
SPRINTF((cp,
"%u", *s++));
268 if (p != 7 || bits > 120)
271 cp +=
SPRINTF((cp,
"%u", *s++));
278 cp +=
SPRINTF((cp,
"%x", *s * 256 + s[1]));
284 (void)
SPRINTF((cp,
"/%u", bits));
285 if (strlen(outbuf) + 1 >
size)
References b, EMSGSIZE, i, size, and SPRINTF.
Referenced by pg_inet_cidr_ntop().
◆ pg_inet_cidr_ntop()
char* pg_inet_cidr_ntop |
( |
int |
af, |
|
|
const void * |
src, |
|
|
int |
bits, |
|
|
char * |
dst, |
|
|
size_t |
size |
|
) |
| |
Definition at line 56 of file inet_cidr_ntop.c.
static char * inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
References EAFNOSUPPORT, inet_cidr_ntop_ipv4(), inet_cidr_ntop_ipv6(), PGSQL_AF_INET, PGSQL_AF_INET6, and size.
Referenced by cidr_abbrev().