RE: Question about adding search domains using kSCPropNetDNSSearchDomains
RE: Question about adding search domains using kSCPropNetDNSSearchDomains
- Subject: RE: Question about adding search domains using kSCPropNetDNSSearchDomains
- From: "Abhishek Singh (abhsing2)" <email@hidden>
- Date: Wed, 8 Oct 2008 21:45:31 +0530
- Thread-topic: Question about adding search domains using kSCPropNetDNSSearchDomains
Title: RE: Question about adding search domains using kSCPropNetDNSSearchDomains
Thanx a lot for the guidance Allan.
But i have even tried the code by always inserting the new element at index value 0. That way i am hoping it works like a stack, pushing the existing elements down and inserting the new element at index 0.
But even that failed and the result was the same. All the domains get added into the same search domain :(
And about using SCNetworkConfiguration APIs, i am coding in the MAC environment for the first time. I learnt this way of adding search domains fro a example code published on the internet. Am i not already using the SCNetworkConfiguration APIs here?
-----Original Message-----
From: Allan Nathanson [mailto:email@hidden]
Sent: Wed 10/8/2008 8:27 PM
To: Abhishek Singh (abhsing2)
Cc: email@hidden
Subject: Re: Question about adding search domains using kSCPropNetDNSSearchDomains
On Oct 8, 2008, at 7:12 AM, Abhishek Singh (abhsing2) wrote:
> Hi all,
>
> I have been struggling for the past 2-3 days to get my code to add
> search domains to the dynamic store.
>
> Right now i am in a state where i am able to add a search domain
> successfully. But if i try to add multiple search domains like
> abc.com pqr.com and xyz.com to the search domains, they all get
> added in the same domain. i.e when i say ping test, the DNS query
> being sent is for "test.abc.com pqr.com xyz.com" instead of sending
> 3 separate queries for "test.abc.com", "test.pqr.com" and "test.xyz.com
> ".
>
> Upon analyzing the output of "scutil --dns" this is what i see
>
> > DNS configuration
> >
> > resolver #1
> > domain : abc.com
> > search domain[0] : abc.com abc.com pqr.com xyz.com
> > search domain[1] : abc.com
> > nameserver[0] : 10.76.11.102
> > order : 200000
> >
> > resolver #2
> > domain : local
> > options : mdns
> > .
> > .
> > .
> > .
> > .
>
> In the above output the source of the problem is very clear. The
> search domain[0] contains all the 3 search domains together. For it
> to work correctly abc.com must be domain[0], pqr.com must be domain
> [1] and xyz.com must be domain[2].
>
> But no matter what i try, the search domains always get appended in
> the domain[0].
>
> The code i am using to insert search domains is as follows
>
> if ( search != NULL && strlen( search ) > 0 )
> {
> CFMutableArrayRef search_list=
> CFArrayCreateMutable(NULL, 0,
>
> &kCFTypeArrayCallBacks);
>
>
> if ( search_list)
> {
>
> /********************************************************************/
> char temp_search
> [1024] = "";
> char *split_names =
> NULL;
>
> safe_strlcpy
> (temp_search, search, sizeof(temp_search));
>
>
> unsigned int i =
> strlen(temp_search);
> int tokens = 0;
> for( ; i > 0; i--)
> {
> if(',' ==
> temp_search[i] || ' ' == temp_search[i])
> {
>
> tokens++;
> }
> }
> tokens++;
>
> i = strlen
> (temp_search);
> for( ; i > 0; i--)
> {
> if(',' ==
> temp_search[i] || ' ' == temp_search[i])
> {
>
> temp_search[i] = NULL;
>
> split_names = &temp_search[i+1];
>
> CFArrayInsertValueAtIndex(search_list, --tokens,
> CFStringCreateWithCString
> ( NULL,
> split_names
> , kCFStringEncodingUTF8 ) );
> }
> }
>
> split_names =
> temp_search;
>
> CFArrayInsertValueAtIndex(search_list, 0,
>
> CFStringCreateWithCString( NULL,
> split_names,
> kCFStringEncodingUTF8 ) );
>
> CFDictionarySetValue
> (dns_new,
>
> kSCPropNetDNSSearchDomains, search_list);
> /********************************************************************/
>
> CFRelease(search_list);
> }
> }
>
>
>
> Can someone please let me know what is it that i am doing wrong here?
>
Bzzzt. From the CFArrayInsertValueAtIndex header doc :
@param idx The index to which to add the new value. If the index is
outside the index space of the array (0 to N inclusive,
where N is the count of the array before the
operation), the
behavior is undefined. If the index is the same as N,
this
function has the same effect as CFArrayAppendValue().
and since you are starting off with an empty array you can't be adding
the first element before index "tokens" since that array index does
not yet exist. Since you are working backwards I think you can always
insert at the beginning.
> If finding the mistake in the above code is going to be difficult,
> it would be a great help if someone could provide me with a sample
> code showing how we can add multiple search domains on MAC.
>
Note: I hope that you are NOT trying to directly update the search
list in the SCDynamicStore. The correct way to update the DNS
settings is to modify the DNS configuration using the
SCNetworkConfiguration APIs.
- Allan
_______________________________________________
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