Go to the source code of this file.
|
typedef void(* | PgIfAddrCallback) (struct sockaddr *addr, struct sockaddr *netmask, void *cb_data) |
|
◆ PgIfAddrCallback
typedef void(* PgIfAddrCallback) (struct sockaddr *addr, struct sockaddr *netmask, 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().