from client program:
#include <IOKit/network/IOEthernetInterface.h>
#include <IOKit/IOType.h>#include <IOKit/network/IOEthernetInterface.h>
int findClassesInIoregistry(io_iterator_t* iterator, char *match_name)
{
CFDictionaryRef classToMatch;
kern_return_t kernResult;
classToMatch = IOServiceMatching(match_name);
if (classToMatch == NULL)
{
return -1;
}
// use class name to match
kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault,
classToMatch, iterator);
classToMatch, iterator);
if (kernResult != KERN_SUCCESS)
{
return -1;
}
return kIOReturnSuccess;
}
io_iterator_t ethernetInterfaceIterator;
result = findClassesInIoregistry(& ethernetInterfaceIterator, kIOEthernetInterfaceIterator);
if(result == kIOReturnSuccess)
{
io_service_t ethernetInterface;
while(ethernetInterface = IOIteratorNext(ethernetInterfaceIterator))
{
NSString *bsdName =
(NSString*)IORegistryEntrySearchCFProperty(ethernetInterface,
NSString *bsdName =
(NSString*)IORegistryEntrySearchCFProperty(ethernetInterface,
kIOServicePlane,
CFSTR("BSD Name"),
kCFAllocatorDefault,
kIORegistryIterateRecursively);
io_service_t ethernetController;
result = IORegistryEntryGetParentEntry(ethernetInterface,
kIOServicePlane,
ðernetController);
if(result == kIOReturnSuccess)
{
IOObjectRelease(ethernetController);
}
IOObjectRelease(ethernetInterface);
}
IOObjectRelease(ethernetInterfaceIterator);
}
if(blockDriverIter)
from driver program:
OSIterator *blockDriverIter = this->getProviderIterator();
com_my_BlockStorageDriver *blockDriver;
{
while (blockDriver = (com_my_BlockStorageDriver*)blockDriverIter->getNextObject())
{
IOLog("blockDriver %p inAct %d\n", blockDriver,
blockDriver->isInactive());
}
blockDriverIter->release();
}
沒有留言:
張貼留言