Replace NULL address family filter by supported address families
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
25198e565b
commit
961706bb48
4 changed files with 29 additions and 5 deletions
|
@ -141,7 +141,7 @@ extern "C" {
|
|||
OSAPI_EXPORT _Success_(return == 0) int
|
||||
os_getifaddrs(
|
||||
_Inout_ os_ifaddrs_t **ifap,
|
||||
_In_opt_ const int *const afs);
|
||||
_In_opt_ const int *afs);
|
||||
|
||||
/**
|
||||
* @brief Free os_ifaddrs_t structure list allocated by os_getifaddrs()
|
||||
|
|
|
@ -45,6 +45,18 @@ const os_in6_addr os_in6addr_loopback = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
|
|||
#define OS_INET_PTON inet_pton
|
||||
#endif
|
||||
|
||||
const int afs[] = {
|
||||
#ifdef __linux
|
||||
AF_PACKET,
|
||||
#endif /* __linux */
|
||||
#if OS_SOCKET_HAS_IPV6
|
||||
AF_INET6,
|
||||
#endif /* OS_SOCKET_HAS_IPV6 */
|
||||
AF_INET
|
||||
};
|
||||
|
||||
const int *const os_supp_afs = afs;
|
||||
|
||||
size_t
|
||||
os_sockaddr_get_size(const os_sockaddr *const sa)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "os/os.h"
|
||||
|
||||
extern const int *const os_supp_afs;
|
||||
|
||||
static int
|
||||
copyaddr(os_ifaddrs_t **ifap, const struct ifaddrs *sys_ifa)
|
||||
{
|
||||
|
@ -55,7 +57,7 @@ copyaddr(os_ifaddrs_t **ifap, const struct ifaddrs *sys_ifa)
|
|||
_Success_(return == 0) int
|
||||
os_getifaddrs(
|
||||
_Inout_ os_ifaddrs_t **ifap,
|
||||
_In_opt_ const int *const afs)
|
||||
_In_opt_ const int *afs)
|
||||
{
|
||||
int err = 0;
|
||||
int use;
|
||||
|
@ -65,6 +67,10 @@ os_getifaddrs(
|
|||
|
||||
assert(ifap != NULL);
|
||||
|
||||
if (afs == NULL) {
|
||||
afs = os_supp_afs;
|
||||
}
|
||||
|
||||
if (getifaddrs(&sys_ifa_root) == -1) {
|
||||
err = errno;
|
||||
} else {
|
||||
|
@ -76,7 +82,7 @@ os_getifaddrs(
|
|||
{
|
||||
sa = sys_ifa->ifa_addr;
|
||||
if (sa != NULL) {
|
||||
use = (afs == NULL);
|
||||
use = 0;
|
||||
for (int i = 0; !use && afs[i] != 0; i++) {
|
||||
use = (sa->sa_family == afs[i]);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "os/os.h"
|
||||
|
||||
extern const int *const os_supp_afs;
|
||||
|
||||
static int
|
||||
getifaces(PIP_ADAPTER_ADDRESSES *ptr)
|
||||
{
|
||||
|
@ -207,7 +209,7 @@ copyaddr(
|
|||
_Success_(return == 0) int
|
||||
os_getifaddrs(
|
||||
_Inout_ os_ifaddrs_t **ifap,
|
||||
_In_opt_ const int *const afs)
|
||||
_In_opt_ const int *afs)
|
||||
{
|
||||
int err = 0;
|
||||
int use;
|
||||
|
@ -219,6 +221,10 @@ os_getifaddrs(
|
|||
|
||||
assert(ifap != NULL);
|
||||
|
||||
if (afs == NULL) {
|
||||
afs = os_supp_afs;
|
||||
}
|
||||
|
||||
ifa = ifa_root = ifa_next = NULL;
|
||||
|
||||
if ((err = getifaces(&ifaces)) == 0 &&
|
||||
|
@ -230,7 +236,7 @@ os_getifaddrs(
|
|||
addr = addr->Next)
|
||||
{
|
||||
sa = (struct sockaddr *)addr->Address.lpSockaddr;
|
||||
use = (afs == NULL);
|
||||
use = 0;
|
||||
for (int i = 0; !use && afs[i] != 0; i++) {
|
||||
use = (afs[i] == sa->sa_family);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue