#include "postgres.h"
#include <unistd.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/file.h>
#include "libpq/ifaddr.h"
#include "port/pg_bswap.h"
#include <sys/ioctl.h>
#include <net/if.h>
Go to the source code of this file.
|
static int | range_sockaddr_AF_INET (const struct sockaddr_in *addr, const struct sockaddr_in *netaddr, const struct sockaddr_in *netmask) |
|
static int | range_sockaddr_AF_INET6 (const struct sockaddr_in6 *addr, const struct sockaddr_in6 *netaddr, const struct sockaddr_in6 *netmask) |
|
int | pg_range_sockaddr (const struct sockaddr_storage *addr, const struct sockaddr_storage *netaddr, const struct sockaddr_storage *netmask) |
|
int | pg_sockaddr_cidr_mask (struct sockaddr_storage *mask, char *numbits, int family) |
|
static void | run_ifaddr_callback (PgIfAddrCallback callback, void *cb_data, struct sockaddr *addr, struct sockaddr *mask) |
|
int | pg_foreach_ifaddr (PgIfAddrCallback callback, void *cb_data) |
|
◆ pg_foreach_ifaddr()
Definition at line 425 of file ifaddr.c.
427 struct sockaddr_in addr;
428 struct sockaddr_storage mask;
429 struct sockaddr_in6 addr6;
432 memset(&addr, 0,
sizeof(addr));
433 addr.sin_family = AF_INET;
434 addr.sin_addr.s_addr =
pg_ntoh32(0x7f000001);
435 memset(&mask, 0,
sizeof(mask));
438 (
struct sockaddr *) &addr,
439 (
struct sockaddr *) &mask);
442 memset(&addr6, 0,
sizeof(addr6));
443 addr6.sin6_family = AF_INET6;
444 addr6.sin6_addr.s6_addr[15] = 1;
445 memset(&mask, 0,
sizeof(mask));
448 (
struct sockaddr *) &addr6,
449 (
struct sockaddr *) &mask);
int pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
static void run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data, struct sockaddr *addr, struct sockaddr *mask)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
References callback(), pg_ntoh32, pg_sockaddr_cidr_mask(), and run_ifaddr_callback().
Referenced by check_same_host_or_net(), and main().
◆ pg_range_sockaddr()
int pg_range_sockaddr |
( |
const struct sockaddr_storage * |
addr, |
|
|
const struct sockaddr_storage * |
netaddr, |
|
|
const struct sockaddr_storage * |
netmask |
|
) |
| |
Definition at line 49 of file ifaddr.c.
53 if (addr->ss_family == AF_INET)
55 (
const struct sockaddr_in *) netaddr,
56 (
const struct sockaddr_in *) netmask);
57 else if (addr->ss_family == AF_INET6)
59 (
const struct sockaddr_in6 *) netaddr,
60 (
const struct sockaddr_in6 *) netmask);
static int range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr, const struct sockaddr_in6 *netaddr, const struct sockaddr_in6 *netmask)
static int range_sockaddr_AF_INET(const struct sockaddr_in *addr, const struct sockaddr_in *netaddr, const struct sockaddr_in *netmask)
References range_sockaddr_AF_INET(), and range_sockaddr_AF_INET6().
Referenced by check_ip().
◆ pg_sockaddr_cidr_mask()
int pg_sockaddr_cidr_mask |
( |
struct sockaddr_storage * |
mask, |
|
|
char * |
numbits, |
|
|
int |
family |
|
) |
| |
Definition at line 105 of file ifaddr.c.
112 bits = (family == AF_INET) ? 32 : 128;
116 bits = strtol(numbits, &endptr, 10);
117 if (*numbits ==
'\0' || *endptr !=
'\0')
125 struct sockaddr_in mask4;
128 if (bits < 0 || bits > 32)
130 memset(&mask4, 0,
sizeof(mask4));
133 maskl = (0xffffffffUL << (32 - (int) bits))
137 mask4.sin_addr.s_addr =
pg_hton32(maskl);
138 memcpy(mask, &mask4,
sizeof(mask4));
144 struct sockaddr_in6 mask6;
147 if (bits < 0 || bits > 128)
149 memset(&mask6, 0,
sizeof(mask6));
150 for (
i = 0;
i < 16;
i++)
153 mask6.sin6_addr.s6_addr[
i] = 0;
155 mask6.sin6_addr.s6_addr[
i] = 0xff;
158 mask6.sin6_addr.s6_addr[
i] =
159 (0xff << (8 - (int) bits)) & 0xff;
163 memcpy(mask, &mask6,
sizeof(mask6));
171 mask->ss_family = family;
References i, and pg_hton32.
Referenced by check_network_callback(), parse_hba_line(), pg_foreach_ifaddr(), and run_ifaddr_callback().
◆ range_sockaddr_AF_INET()
static int range_sockaddr_AF_INET |
( |
const struct sockaddr_in * |
addr, |
|
|
const struct sockaddr_in * |
netaddr, |
|
|
const struct sockaddr_in * |
netmask |
|
) |
| |
|
static |
Definition at line 66 of file ifaddr.c.
70 if (((addr->sin_addr.s_addr ^ netaddr->sin_addr.s_addr) &
71 netmask->sin_addr.s_addr) == 0)
Referenced by pg_range_sockaddr().
◆ range_sockaddr_AF_INET6()
static int range_sockaddr_AF_INET6 |
( |
const struct sockaddr_in6 * |
addr, |
|
|
const struct sockaddr_in6 * |
netaddr, |
|
|
const struct sockaddr_in6 * |
netmask |
|
) |
| |
|
static |
Definition at line 78 of file ifaddr.c.
84 for (
i = 0;
i < 16;
i++)
86 if (((addr->sin6_addr.s6_addr[
i] ^ netaddr->sin6_addr.s6_addr[
i]) &
87 netmask->sin6_addr.s6_addr[
i]) != 0)
References i.
Referenced by pg_range_sockaddr().
◆ run_ifaddr_callback()
static void run_ifaddr_callback |
( |
PgIfAddrCallback |
callback, |
|
|
void * |
cb_data, |
|
|
struct sockaddr * |
addr, |
|
|
struct sockaddr * |
mask |
|
) |
| |
|
static |
Definition at line 181 of file ifaddr.c.
184 struct sockaddr_storage fullmask;
192 if (mask->sa_family != addr->sa_family)
196 else if (mask->sa_family == AF_INET)
198 if (((
struct sockaddr_in *) mask)->sin_addr.s_addr == INADDR_ANY)
201 else if (mask->sa_family == AF_INET6)
203 if (IN6_IS_ADDR_UNSPECIFIED(&((
struct sockaddr_in6 *) mask)->sin6_addr))
212 mask = (
struct sockaddr *) &fullmask;
215 (*callback) (addr, mask, cb_data);
References pg_sockaddr_cidr_mask().
Referenced by pg_foreach_ifaddr().