Re: [SystemConfiguration] How to be informed when the router IP address is available/known
Re: [SystemConfiguration] How to be informed when the router IP address is available/known
- Subject: Re: [SystemConfiguration] How to be informed when the router IP address is available/known
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 29 May 2012 16:34:47 +0000
- Acceptlanguage: en-US
- Thread-topic: [SystemConfiguration] How to be informed when the router IP address is available/known
On May 29, 2012, at 5:38 PM, Allan Nathanson wrote:
>
> On May 29, 2012, at 10:14 AM, Stéphane Sudre <email@hidden> wrote:
>
>> Problem:
>> --------
>>
>> When the System Configuration framework notifies of a change for the kSCEntNetIPv4 global entity, the router IP address is not set and no later notifications are performed.
>>
>> Discussion:
>> -----------
>>
>> I'm looking into finding the router IP address attached to the primary IPv4 (and IPv6) configuration.
>>
>> I registered as an observer for the kSCEntNetIPv4 (and kSCEntNetIPv6) global entities.
>>
>> Depending on the configuration method (Manual or not), I use different code to get the router IP address.
>>
>> In the case of a manual IPv4 configuration, I check the value associated to the kSCPropNetIPv4Router key.
>>
>>
>> The issue is that this value is not always set when the SCDynamicStoreCallBack is invoked.
>>
>> And no other notifications are sent later when the Router IP address is set for the kSCPropNetIPv4Router key.
>>
>>
>> Example:
>> --------
>>
>> In the System Preferences > Network pane, the Ethernet interface is configured manually with these very original values:
>>
>> IP Address: 192.168.1.1
>> Subnet Mask: 255.255.255.0
>> Router: 192.168.1.251
>>
>> 1. You set an empty string for "Router" and then click apply.
>>
>> => The SCDynamicStoreCallBack callback is invoked. OK fine.
>>
>> 2. You set 192.168.1.251 for "Router" and then click apply.
>>
>> => The SCDynamicStoreCallBack callback is invoked. But the kSCPropNetIPv4Router is not set. Would you wait a bit before looking for this key, you would get a result.
>>
>>
>> Question:
>> ---------
>>
>> Is there a way to be notified when the kSCPropNetIPv4Router key is changed?
>
> For a manual configuration, the router address is stored as part of the persistent configuration and would only show up in the SCDynamicStore's "Setup:" (kSCDynamicStoreDomainSetup) keys.
>
> ... and I suspect that your SCDynamicStore monitoring code is only watching for changes to the "State:" (kSCDynamicStoreDomainState) keys.
It was only watching for this key: SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv4)
Now, I changed it to watch for these keys:
SCDynamicStoreKeyCreateNetworkServiceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, (CFStringRef)tPrimaryServiceKey,kSCEntNetIPv4)
SCDynamicStoreKeyCreateNetworkServiceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainSetup, (CFStringRef)tPrimaryServiceKey,kSCEntNetIPv4)
It works better _but_ there's always a point when the Router IP address is not found and from them it never re-appears. ( I repeatedly set/unset the Router text field (and click Apply in the SysPrefs > Network pane).
_______________________________________________
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