• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Network location question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Network location question


  • Subject: Re: Network location question
  • From: Allan Nathanson <email@hidden>
  • Date: Wed, 3 Aug 2005 12:16:24 -0400

Mike -

You are mixing the SCPreferences and SCDynamicStore APIs. The former provides access to the stored configuration while the latter provides access to the active configuration.

If you switch your code to use :

    scpref = SCPreferencesCreate(NULL,CFSTR("TEST"),NULL);

you should receive a callback whenever the stored configuration gets updated. Of course, a change to the stored configuration may or may not reflect a "network location" change.

If you want to watch for changes to the SCDynamicStore keys then you will need to use the SCDynamicStore APIs.

Taking a step backwards I'd like to ask for your own definition of a "network location" change? Are you simply interested in the "network location" that you'd see from the Finder's "Location" menu? or are you really interested in the actual configuration of the network (IP addresses, DNS configuration, etc)? Is this for an application that needs to be "network aware" (not connected vs. connected)?

- Allan

p.s. you also need to understand than the network configuration changes are all done asynchronously. Changing the "location" from the Finder simply starts the gears rolling. We don't currently have a good way to say "OK, the change has completed".



On Aug 3, 2005, at 11:47 AM, Mike Laster wrote:

How can I detect when the network location has been changed? I figure it is something to do with the System Configuration framework, but I can't find much documentation on it.

What I want to do is write a program to be able detect network location changes and then run a script when this occurs.

This is the direction I'm going now (which doesn't work):

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>

void sc_callback(SCPreferencesRef prefs,
                 SCPreferencesNotification notificationType,
                 void *info)
{
    NSLog(@"callback called!");
}

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    SCPreferencesRef scpref = NULL;
    SCPreferencesContext prefcontext;
    CFRunLoopRef rlref = NULL;

    bzero(&prefcontext,sizeof(SCPreferencesContext));

scpref = SCPreferencesCreate(NULL,CFSTR("TEST"),CFSTR("Setup:/ Network/Global/IPv4"));
SCPreferencesSetCallback(scpref,sc_callback,&prefcontext);


    rlref = [[NSRunLoop currentRunLoop] getCFRunLoop];

SCPreferencesScheduleWithRunLoop (scpref,rlref,kCFRunLoopDefaultMode);
[[NSRunLoop currentRunLoop] run];


    if (scpref != NULL)
    {
        CFRelease(scpref);
        scpref = NULL;
    }

    [pool release];
    return 0;
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog 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. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Network location question (From: Mike Laster <email@hidden>)

  • Prev by Date: Network location question
  • Next by Date: Re: Network location question
  • Previous by thread: Network location question
  • Next by thread: Re: Network location question
  • Index(es):
    • Date
    • Thread