SCNetworkInterfaceGetConfiguration always returns NULL.

  • Hi,

    So I'm attempting to use the system configuration framework to
    determine if a network interface is active.  If there are no active
    network interfaces then I want to disable some options...

    I'm using MoreSCF as an example, but I get thinks to work properly
    because SCNetworkInterfaceGetConfiguration always returns NULL.  The
    docs state that this means the passed in interface reference isn't
    active, but I'm have an active Airport connection when I run these
    tests.  Other functions like
    SCNetworkInterfaceGetHardwareAddressString and
    SCNetworkInterfaceGetBSDName work fine...

    Here's the code I'm using.  Any thoughts?  I'm a total CF noob, so be
    easy on me if I haven't done anything correctly.  :-)

    extern Boolean ActiveNetworkConnection()
    {
        Boolean        isNetworkActive = false;
        CFArrayRef          interfaces;
        CFIndex            interfaceCount;
        CFIndex            interfaceIndex;
        CFMutableArrayRef  result;
    CFArrayRef *portArray;

    portArray = NULL;
        result = NULL;
        interfaces = NULL;

        if (SCNetworkInterfaceCopyAll != NULL) {
            interfaces = SCNetworkInterfaceCopyAll();
    }

    interfaceCount = CFArrayGetCount(interfaces);

    for (interfaceIndex = 0; interfaceIndex < interfaceCount;
    interfaceIndex++) {
      Boolean                skipIt;
      SCNetworkInterfaceRef  thisInterface;
      CFDictionaryRef  interfaceConfig;
      skipIt = false;

      thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex);
      assert(thisInterface != NULL);

      interfaceConfig = SCNetworkInterfaceGetConfiguration(thisInterface);
      if (interfaceConfig != NULL) {
      isNetworkActive = true;
      } else {
      skipIt = true;
      }
    }
    return isNetworkActive;
    }

    So I'm attempting to use the system configuration framework to
    determine if a network interface is active.  If there are no active
    network interfaces then I want to disable some options...
  • On Nov 11, 2007, at 5:36 PM, Adhamh Findlay wrote:

    > Hi,
    >
    > So I'm attempting to use the system configuration framework to
    > determine if a network interface is active.  If there are no active
    > network interfaces then I want to disable some options...
    >
    > I'm using MoreSCF as an example, but I get thinks to work properly
    > because SCNetworkInterfaceGetConfiguration always returns NULL.  The
    > docs state that this means the passed in interface reference isn't
    > active, but I'm have an active Airport connection when I run these
    > tests.  Other functions like
    > SCNetworkInterfaceGetHardwareAddressString and
    > SCNetworkInterfaceGetBSDName work fine...
    >
    > Here's the code I'm using.  Any thoughts?  I'm a total CF noob, so
    > be easy on me if I haven't done anything correctly.  :-)

    It was suggested that I use CFShow to print the thisInterface refer to
    make sure it was the right type.  So I added CFShow(thisInterface) in
    the for loop and for every interface a SCNetworkInterface ref is
    printed.  So I do have the right type.

    Could this be a Leopard bug?
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today