#include "postgres.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include "utils/builtins.h"
#include "utils/inet.h"
Go to the source code of this file.
|
static int | inet_net_pton_ipv4 (const char *src, u_char *dst) |
|
static int | inet_cidr_pton_ipv4 (const char *src, u_char *dst, size_t size) |
|
static int | inet_net_pton_ipv6 (const char *src, u_char *dst) |
|
static int | inet_cidr_pton_ipv6 (const char *src, u_char *dst, size_t size) |
|
int | pg_inet_net_pton (int af, const char *src, void *dst, size_t size) |
|
static int | getbits (const char *src, int *bitsp) |
|
static int | getv4 (const char *src, u_char *dst, int *bitsp) |
|
◆ NS_IN6ADDRSZ
◆ NS_INADDRSZ
◆ NS_INT16SZ
◆ getbits()
static int getbits |
( |
const char * |
src, |
|
|
int * |
bitsp |
|
) |
| |
|
static |
◆ getv4()
static int getv4 |
( |
const char * |
src, |
|
|
u_char * |
dst, |
|
|
int * |
bitsp |
|
) |
| |
|
static |
◆ inet_cidr_pton_ipv4()
static int inet_cidr_pton_ipv4 |
( |
const char * |
src, |
|
|
u_char * |
dst, |
|
|
size_t |
size |
|
) |
| |
|
static |
Definition at line 97 of file inet_net_pton.c.
99 static const char xdigits[] =
"0123456789abcdef";
100 static const char digits[] =
"0123456789";
106 const u_char *odst = dst;
109 if (ch ==
'0' && (src[0] ==
'x' || src[0] ==
'X')
110 && isxdigit((
unsigned char) src[1]))
117 while ((ch = *src++) !=
'\0' && isxdigit((
unsigned char) ch))
119 if (isupper((
unsigned char) ch))
120 ch = tolower((
unsigned char) ch);
121 n = strchr(xdigits, ch) - xdigits;
122 assert(n >= 0 && n <= 15);
126 tmp = (tmp << 4) | n;
131 *dst++ = (u_char) tmp;
139 *dst++ = (u_char) (tmp << 4);
142 else if (isdigit((
unsigned char) ch))
156 }
while ((ch = *src++) !=
'\0' &&
157 isdigit((
unsigned char) ch));
160 *dst++ = (u_char) tmp;
161 if (ch ==
'\0' || ch ==
'/')
166 if (!isdigit((
unsigned char) ch))
174 if (ch ==
'/' && isdigit((
unsigned char) src[0]) && dst > odst)
185 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
204 else if (*odst >= 224)
206 else if (*odst >= 192)
208 else if (*odst >= 128)
214 if (bits < ((dst - odst) * 8))
215 bits = (dst - odst) * 8;
221 if (bits == 8 && *odst == 224)
225 while (bits > ((dst - odst) * 8))
static pg_noinline void Size size
References assert, digits, EMSGSIZE, and size.
Referenced by pg_inet_net_pton().
◆ inet_cidr_pton_ipv6()
static int inet_cidr_pton_ipv6 |
( |
const char * |
src, |
|
|
u_char * |
dst, |
|
|
size_t |
size |
|
) |
| |
|
static |
Definition at line 439 of file inet_net_pton.c.
441 static const char xdigits_l[] =
"0123456789abcdef",
442 xdigits_u[] =
"0123456789ABCDEF";
470 while ((ch = *src++) !=
'\0')
474 if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
475 pch = strchr((xdigits = xdigits_u), ch);
479 val |= (pch - xdigits);
495 else if (*src ==
'\0')
499 *tp++ = (u_char) (
val >> 8) & 0xff;
500 *tp++ = (u_char)
val & 0xff;
507 getv4(curtok, tp, &bits) > 0)
513 if (ch ==
'/' &&
getbits(src, &bits) > 0)
521 *tp++ = (u_char) (
val >> 8) & 0xff;
522 *tp++ = (u_char)
val & 0xff;
535 const int n = tp - colonp;
540 for (
i = 1;
i <= n;
i++)
542 endp[-
i] = colonp[n -
i];
static int getv4(const char *src, u_char *dst, int *bitsp)
References digits, EMSGSIZE, getbits(), getv4(), i, NS_IN6ADDRSZ, NS_INADDRSZ, NS_INT16SZ, size, and val.
Referenced by inet_net_pton_ipv6(), and pg_inet_net_pton().
◆ inet_net_pton_ipv4()
static int inet_net_pton_ipv4 |
( |
const char * |
src, |
|
|
u_char * |
dst |
|
) |
| |
|
static |
Definition at line 260 of file inet_net_pton.c.
262 static const char digits[] =
"0123456789";
263 const u_char *odst = dst;
271 while (ch = *src++, isdigit((
unsigned char) ch))
282 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
285 *dst++ = (u_char) tmp;
286 if (ch ==
'\0' || ch ==
'/')
294 if (ch ==
'/' && isdigit((
unsigned char) src[0]) && dst > odst)
305 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
330 if ((bits / 8) > (dst - odst))
References assert, digits, EMSGSIZE, and size.
Referenced by pg_inet_net_pton().
◆ inet_net_pton_ipv6()
static int inet_net_pton_ipv6 |
( |
const char * |
src, |
|
|
u_char * |
dst |
|
) |
| |
|
static |
◆ pg_inet_net_pton()
int pg_inet_net_pton |
( |
int |
af, |
|
|
const char * |
src, |
|
|
void * |
dst, |
|
|
size_t |
size |
|
) |
| |
Definition at line 62 of file inet_net_pton.c.
static int inet_net_pton_ipv6(const char *src, u_char *dst)
static int inet_net_pton_ipv4(const char *src, u_char *dst)
static int inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size)
References EAFNOSUPPORT, inet_cidr_pton_ipv4(), inet_cidr_pton_ipv6(), inet_net_pton_ipv4(), inet_net_pton_ipv6(), PGSQL_AF_INET, PGSQL_AF_INET6, and size.
Referenced by network_in().