Re: Porblems passing PPP options to SCNetworkConnectionStart
Re: Porblems passing PPP options to SCNetworkConnectionStart
- Subject: Re: Porblems passing PPP options to SCNetworkConnectionStart
- From: Allan Nathanson <email@hidden>
- Date: Tue, 6 Mar 2007 09:05:24 -0500
From <SystemConfiguration/SCNetworkConnection.h>,
SCNetworkConnectionStart() :
@param userOptions The options dictionary to start the
connection with.
If userOptions is NULL, the default settings will be
used.
If userOptions are specified, they must be in the
same format
as network services stored in the system configuration
preferences schema. The options will override the
default
settings defined for the service.
And if you look at how the configuration of a network service has been
setup you'll note that your passed in options need an extra level.
The userOptions should look something like :
<dict>
<key>PPP</key>
<dict>
<key>AuthName</key>
<string>email@hidden</string>
...
</dict>
<key>Modem</key>
<dict>
<key>Speaker</key>
<integer>1</integer>
</dict>
</dict>
And, of course, if you don't have any "Modem" options to change than
those overrides need not be specified.
In code (and starting with your example) you'd want something like :
CFStringRef keys[3] = { NULL, NULL, NULL };
CFStringRef vals[3] = { NULL, NULL, NULL };
CFIndex numkeys = 0;
keys[numkeys] = kSCPropNetPPPAuthName;
vals[numkeys++] = CFSTR("email@hidden");
keys[numkeys] = kSCPropNetPPPAuthPassword;
vals[numkeys++] = CFSTR("bogus");
keys[numkeys] = kSCPropNetPPPCommRemoteAddress;
vals[numkeys++] = CFSTR("1234567890");
// create "PPP" options
pppOptionsForDial = CFDictionaryCreate(NULL, (const void **)&keys,
(const void **)&vals, numkeys, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
numkeys = 0;
keys[numkeys] = kSCEntNetPPP;
vals[numkeys++] = pppOptionsForDial;
// create "connection" options
optionsForDial = CFDictionaryCreate(NULL, (const void **)&keys,
(const void **)&vals, numkeys, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (err == 0) {
ok =
SCNetworkConnectionStart(m_hActiveConnection,optionsForDial,false);
if ( ! ok ) {
err = SCError();
}
}
CFRelease(optionsForDial);
CFRelease(pppOptionsForDial);
Hope this helps.
- Allan
On Mar 6, 2007, at 4:22 AM, Luis Soltero wrote:
Hello All,
It seems that several people on this list are developing custom
dialup applications and all seem to be having problems passing PPP
options to SCNetworkConnectionStart().
Here are two recent posts requesting help on this issue
http://lists.apple.com/archives/macnetworkprog/2007/Feb/msg00026.html
http://lists.apple.com/archives/Macnetworkprog/2007/Feb/msg00004.html
The common thread to the problem is that no matter how you create
the options dictionary, SCNetworkConnectionStart() just ignores the
options.
Here is my attempt to override the username, password, and phone
number coded in the PPP network settings for the default location.
This code is based on the developer.apple.com sample dialer
CFStringRef keys[3] = { NULL, NULL, NULL };
CFStringRef vals[3] = { NULL, NULL, NULL };
CFIndex numkeys = 0;
keys[numkeys] = kSCPropNetPPPAuthName;
vals[numkeys++] = CFSTR("email@hidden");
keys[numkeys] = kSCPropNetPPPAuthPassword;
vals[numkeys++] = CFSTR("bogus");
keys[numkeys] = kSCPropNetPPPCommRemoteAddress;
vals[numkeys++] = CFSTR("1234567890");
optionsForDial = CFDictionaryCreate(NULL, (const void
**)&keys, (const void **)&vals, numkeys,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (err == 0) {
ok =
SCNetworkConnectionStart(m_hActiveConnection,optionsForDial,false);
if ( ! ok ) {
err = SCError();
}
the connection is dialed using the values in the network preferences
and the optional values passed in optionsForDial are ignored.
a variation of a recent posting which attempts to disable the alerts
also fails.
CFMutableDictionaryRef dicc;
if (optionsForDial!=NULL) {
dicc = CFDictionaryCreateMutableCopy(NULL, 0,
optionsForDial);
} else {
dicc = CFDictionaryCreateMutable(NULL, 0,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
int elementValue = 0;
CFNumberRef elementNumRef =
CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &elementValue);
CFDictionaryAddValue (dicc,CFSTR("AlertEnable"),
elementNumRef);
CFRelease(elementNumRef);
optionsForDial = dicc;
// Initiate the connection.
if (err == 0) {
ok =
SCNetworkConnectionStart(m_hActiveConnection,optionsForDial,false);
if ( ! ok ) {
err = SCError();
}
}
the docs state this http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_ReachConnect/chapter_5_section_5.html#/
/apple_ref/doc/uid/TP40001065-CH204-TPXREF107
By default, the SCNetworkConnectionStart function uses the user’s
preferred connection settings to start the connection. You can,
however, provide a dictionary of values to override some of these
settings for the duration of the connection.
If you do provide a dictionary of additional settings be aware that:
The dictionary must be in the correct format for a network service
dictionary (described in “The NetworkServices Dictionary”). If you
do not follow this format precisely, the PPP controller may ignore
the dictionary.
The PPP controller merges the settings you provide with the user’s
existing settings before the connection is established, ignoring any
inappropriate values in your dictionary.
which leads me to conclude
a) that SCNetworkConnectionStart is busted.
or
b) we dont know how to create a dictionary in the proper "network
services dictionary" format.
or
c) the values that we are trying to modify are inappropriate and
therefore being ignored.
Can anyone shed any light on this issue? Can anyone provide us with
a code sample that builds a dictionary in the appropriate format and
successfully changes some of the default PPP options before dialing.
Any help on this matter is greatly appreciated.
Thanks in advanced for your help.
--luis
--
Luis Soltero, Ph.D., MCS
Director of Software Development, CTO
Global Marine Networks, LLC
StarPilot, LLC
Tel: 865-379-8723
Fax: 865-681-5017
E-Mail: email@hidden
Web: http://www.globalmarinenet.net
Web: http://www.starpilotllc.com
_______________________________________________
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