Re: problem with ifnet_get_address_list_family on Lion
Re: problem with ifnet_get_address_list_family on Lion
- Subject: Re: problem with ifnet_get_address_list_family on Lion
- From: Michael Tüxen <email@hidden>
- Date: Tue, 09 Aug 2011 20:26:22 +0200
... the following works on Lion (same code on Leopard and SnowLeopard):
static void
sctp_init_ifns_for_vrf(int vrfid)
{
/* Here we must apply ANY locks needed by the
* IFN we access and also make sure we lock
* any IFA that exists as we float through the
* list of IFA's
*/
errno_t error;
ifnet_t *ifnetlist;
uint32_t i, count;
char name[SCTP_IFNAMSIZ];
struct ifnet *ifn;
struct ifaddr *ifa;
struct in6_ifaddr *ifa6;
struct sctp_ifa *sctp_ifa;
uint32_t ifa_flags;
ifnetlist = NULL;
count = 0;
error = ifnet_list_get(IFNET_FAMILY_ANY, &ifnetlist, &count);
if (error != 0) {
printf("ifnet_list_get failed %d\n", error);
goto out;
}
for (i = 0; i < count; i++) {
ifn = ifnetlist[i];
if (SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) && sctp_is_vmware_interface(ifn)) {
continue;
}
TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
if (ifa->ifa_addr == NULL) {
continue;
}
if ((ifa->ifa_addr->sa_family != AF_INET) && (ifa->ifa_addr->sa_family != AF_INET6)) {
/* non inet/inet6 skip */
continue;
}
if (ifa->ifa_addr->sa_family == AF_INET6) {
if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) {
/* skip unspecifed addresses */
continue;
}
} else {
if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) {
continue;
}
}
if (sctp_is_desired_interface_type(ifa) == 0) {
/* non desired type */
continue;
}
if (ifa->ifa_addr->sa_family == AF_INET6) {
ifa6 = (struct in6_ifaddr *)ifa;
ifa_flags = ifa6->ia6_flags;
} else {
ifa_flags = 0;
}
snprintf(name, SCTP_IFNAMSIZ, "%s%d", ifn->if_name, ifn->if_unit);
sctp_ifa = sctp_add_addr_to_vrf(vrfid,
(void *)ifn,
ifn->if_index,
ifn->if_type,
name,
(void *)ifa,
ifa->ifa_addr,
ifa_flags,
0);
if (sctp_ifa) {
sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
}
}
}
out:
if (ifnetlist != 0)
ifnet_list_free(ifnetlist);
}
I hope this helps.
Best regards
Michael
On Aug 9, 2011, at 8:13 PM, Vincent Lubet wrote:
> Hi Richard,
>
> If you did not get a reply yet, I would suggest that you file a bug report at https://bugreporter.apple.com/
>
> Vincent
>
> On Jul 22, 2011, at 2:26 PM, Richard Hood wrote:
>
>> now that we can talk about Lion . . .
>>
>> I'm having some problems with ifnet_get_address_list_family() on Lion.
>>
>> at startup my kext gets all the active IP interfaces on the system.
>> the problem is that on Lion I'm getting an ENXIO (device not configured) error whereas on Snow Leopard this code is working fine.
>> however, once the systems has booted, if I stop the kext and restart it the call seems to work fine.
>> anyone know what has changed in Lion with-respect-to ifnet_get_address_list_family()?
>>
>> the code looks something like this . . .
>>
>> ifnet_t *interfaces = NULL;
>> u_int32_t cnt = nInfos;
>> int err = ifnet_list_get(IFNET_FAMILY_ETHERNET, &interfaces, &cnt);
>> if (err)
>> {
>> NETLOG(("ifnet_list_get: error=%d\n", err));
>> return 0;
>> }
>>
>> NETLOG(("Interface count=%d\n", cnt));
>>
>> int i;
>> int mm=0;
>> for (i=0;i<cnt;i++)
>> {
>> u_int16_t flags = ifnet_flags(interfaces[i]);
>>
>> NETLOG(("Interface %p flags=0x%x\n", interfaces[i], flags));
>>
>> if (!(flags & IFF_UP))
>> continue;
>>
>> ifaddr_t *addrList;
>> err = ifnet_get_address_list_family(interfaces[i], &addrList, PF_INET);
>> if (err)
>> {
>> NETLOG(("ifnet_get_address_list_family: error=%d\n", err));
>> continue;
>> }
>>
>>
>> [ code snipped ]
>>
>>
>> }
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-kernel mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden