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()
Definition at line 85 of file inet_cidr_ntop.c.
86{
88 char *t;
91
93 {
96 }
97
98 if (bits == 0)
99 {
100 if (size < sizeof "0")
103 size--;
105 }
106
107
108 for (
b = bits / 8;
b > 0;
b--)
109 {
110 if (size <= sizeof "255.")
115 {
118 }
120 }
121
122
125 {
126 if (size <= sizeof ".255")
131 m = ((1 <<
b) - 1) << (8 -
b);
134 }
135
136
137 if (size <= sizeof "/32")
141
145}
References b, EMSGSIZE, fb(), and SPRINTF.
Referenced by pg_inet_cidr_ntop().
◆ inet_cidr_ntop_ipv6()
Definition at line 165 of file inet_cidr_ntop.c.
166{
169 int p;
176 unsigned char inbuf[16];
177 char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
179 int words;
181
183 {
186 }
187
189
190 if (bits == 0)
191 {
195 }
196 else
197 {
198
199 p = (bits + 7) / 8;
204 {
205 m = ((
u_int) ~0) << (8 -
b);
207 }
208
210
211
212 words = (bits + 15) / 16;
213 if (words == 1)
214 words = 2;
215
216
218 for (
i = 0;
i < (words * 2);
i += 2)
219 {
220 if ((s[
i] | s[
i + 1]) == 0)
221 {
225 }
226 else
227 {
229 {
233 }
234 }
235 }
236
238 {
241 }
242
244 ((
zero_l == 5 && s[10] == 0xff && s[11] == 0xff) ||
245 ((
zero_l == 7 && s[14] != 0 && s[15] != 1)))))
247
248
249 for (p = 0; p < words; p++)
250 {
252 {
253
256 if (p == words - 1)
258 s++;
259 s++;
260 continue;
261 }
262
264 {
265 *
cp++ = (p == 6) ?
':' :
'.';
267
268 if (p != 7 || bits > 120)
269 {
272 }
273 }
274 else
275 {
279 s += 2;
280 }
281 }
282 }
283
285 if (
strlen(outbuf) + 1 > size)
288
290
294}
References b, EMSGSIZE, fb(), i, and SPRINTF.
Referenced by pg_inet_cidr_ntop().
◆ pg_inet_cidr_ntop()
Definition at line 56 of file inet_cidr_ntop.c.
57{
58 switch (af)
59 {
64 default:
67 }
68}
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, fb(), inet_cidr_ntop_ipv4(), inet_cidr_ntop_ipv6(), PGSQL_AF_INET, and PGSQL_AF_INET6.
Referenced by cidr_abbrev().