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
|