Skip to content

Fix build with Android 26 NDK (which has some nullability annotations) #97976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/native/libs/System.Native/pal_interfaceaddresses.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static inline uint8_t mask2prefix(uint8_t* mask, int length)
static int (*getifaddrs)(struct ifaddrs**) = NULL;
static void (*freeifaddrs)(struct ifaddrs*) = NULL;

static void try_loading_getifaddrs()
static void try_loading_getifaddrs(void)
{
if (android_get_device_api_level() >= 24)
{
Expand All @@ -139,7 +139,7 @@ static void try_loading_getifaddrs()
}
}

static bool ensure_getifaddrs_is_loaded()
static bool ensure_getifaddrs_is_loaded(void)
{
static pthread_once_t getifaddrs_is_loaded = PTHREAD_ONCE_INIT;
pthread_once(&getifaddrs_is_loaded, try_loading_getifaddrs);
Expand Down Expand Up @@ -169,11 +169,12 @@ int32_t SystemNative_EnumerateInterfaceAddresses(void* context,

for (struct ifaddrs* current = headAddr; current != NULL; current = current->ifa_next)
{
if (current->ifa_addr == NULL)
char *ifa_name = current->ifa_name;
if (current->ifa_addr == NULL || ifa_name == NULL)
{
continue;
}
uint32_t interfaceIndex = if_nametoindex(current->ifa_name);
uint32_t interfaceIndex = if_nametoindex(ifa_name);
// ifa_name may be an aliased interface name.
// Use if_indextoname to map back to the true device name.
char actualName[IF_NAMESIZE];
Expand Down Expand Up @@ -376,9 +377,17 @@ int32_t SystemNative_GetNetworkInterfaces(int32_t * interfaceCount, NetworkInter

while (ifaddrsEntry != NULL)
{
char *ifa_name = ifaddrsEntry->ifa_name;

if (ifa_name == NULL)
{
ifaddrsEntry = ifaddrsEntry->ifa_next;
continue;
}

//current = NULL;
nii = NULL;
uint ifindex = if_nametoindex(ifaddrsEntry->ifa_name);
uint ifindex = if_nametoindex(ifa_name);
for (index = 0; index < (int)ifcount; index ++)
{
if (((NetworkInterfaceInfo*)memoryBlock)[index].InterfaceIndex == ifindex)
Expand All @@ -393,8 +402,8 @@ int32_t SystemNative_GetNetworkInterfaces(int32_t * interfaceCount, NetworkInter
// We git new interface.
nii = &((NetworkInterfaceInfo*)memoryBlock)[ifcount++];

memcpy(nii->Name, ifaddrsEntry->ifa_name, sizeof(nii->Name));
nii->InterfaceIndex = if_nametoindex(ifaddrsEntry->ifa_name);
memcpy(nii->Name, ifa_name, sizeof(nii->Name));
nii->InterfaceIndex = ifindex;
nii->Speed = -1;
nii->HardwareType = ((ifaddrsEntry->ifa_flags & IFF_LOOPBACK) == IFF_LOOPBACK) ? NetworkInterfaceType_Loopback : NetworkInterfaceType_Unknown;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct CipherInfo
} CipherInfo;

#define DEFINE_CIPHER(cipherId, width, javaName, flags) \
CipherInfo* AndroidCryptoNative_ ## cipherId() \
CipherInfo* AndroidCryptoNative_ ## cipherId(void) \
{ \
static CipherInfo info = { flags, width, javaName }; \
return &info; \
Expand Down