OSX Monitoring System Network settings

Source: Internet
Author: User

Due to the needs of daily development, we need to listen to the changes in some of OSX's system settings, to achieve the synchronization of software program settings, we can listen to the following functions to change the system settings:

#include <SystemConfiguration/SystemConfiguration.h>

//------------------------------------------------------------------
Scdynamicstoreref Dynstore;
Scdynamicstorecontext context = {0, this, NULL, NULL, NULL};
Dynstore = Scdynamicstorecreate (Kcfallocatordefault,
Cfbundlegetidentifier (Cfbundlegetmainbundle ()),
systemproxychangecallback,//Custom callback function, note "1"
&context);
Const CFSTRINGREF Keys[3] = {cfstr ("state:/network/global/proxies")};//get system proxy settings, note "2"
Cfarrayref Watchedkeys = cfarraycreate (Kcfallocatordefault,
(const void * *) keys,
1,
&kcftypearraycallbacks);
if (Scdynamicstoresetnotificationkeys (Dynstore, NULL, Watchedkeys))
{
Cfrelease (Watchedkeys);
Cfrunloopsourceref rlsrc = Scdynamicstorecreaterunloopsource (Kcfallocatordefault, DynStore, 0);
Cfrunloopaddsource (Cfrunloopgetcurrent (), RLSRC, Kcfrunloopdefaultmode);
Cfrelease (RLSRC);
}
Else
{
Cfrelease (Watchedkeys);
Cfrelease (Dynstore);
Dynstore = NULL;
}
//------------------------------------------------------------------
Cfrunlooprun (); You need to call this function in the program to listen to the effect

//================================================

Note "1", when the system settings are changed, the callback function will be triggered, according to the specific needs of the relevant operation processing

void Systemproxychangecallback (Scdynamicstoreref store, cfarrayref changedkeys,void *info)
{
}

Note "2", here the demo program for monitoring network agents to change the properties of the settings, other property values can be consulted:

Https://developer.apple.com/library/mac/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_ Understandschema/sc_understandschema.html

OSX Monitoring System Network settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.