Hi;
This is the code that collects the DNS servers and return it to the caller
The code works OK but it is not optimized and may leak, if someone
improves it
please post it to the list.
The function is placed in a .m file to be compiled with obj-c.
The function gets called by *sres_parse_resolv_conf* in sres.c
The code looks like:
#ifdef HAVE_IPHONE_OS
// [DB] For iPhone
char const *names[SRES_MAX_NAMESERVERS];
int count=sres_parse_iphone_ip(c, names);
if(i> 0){
int j=0;
for(j=0; j<count;j++)
sres_parse_nameserver(c, names[j]);
}
///////////////////////////
#endif
char const **names must be supplied by the caller and MUST have space for
SRES_MAX_NAMESERVERS char pointers.
Form the function we also can get the domain name ( NSString *domainName
) it can be set as
an environment variable or into the sres_config structure.
#import<Foundation/Foundation.h>
#include "sofia-resolv/sres.h"
typedef struct sres_config sres_config_t;
/**
* Uses IPHONE to get DNS servers list.
*/
int sres_parse_iphone_ip(sres_config_t *c, char const **names)
{
NSDictionary *dictionary = [NSDictionary
dictionaryWithContentsOfFile:@"/private/var/preferences/SystemConfiguration/com.apple.network.identification.plist"];
NSArray *signatures = [dictionary valueForKey:@"Signatures"];
NSDictionary *item1 = [signatures objectAtIndex:0];
NSDictionary *dns = [[[item1 valueForKey:@"Services"] objectAtIndex:0]
valueForKey:@"DNS"];
NSString *domainName = [dns valueForKey:@"DomainName"];
NSArray *dnsServerAddress = [dns valueForKey:@"ServerAddresses"];
NSEnumerator *enumerator = [dnsServerAddress objectEnumerator];
NSString *serveraddr;
int i=0;
while (serveraddr = (NSString *)[enumerator nextObject]){
names[i++] = [serveraddr UTF8String];
// take only SRES_MAX_NAMESERVERS nameservers
if(i == SRES_MAX_NAMESERVERS)
break;
}
return i;
}
Regards
Inca R
Andrew Rechenberg Lists wrote:
I'd be interested in that patch. I'd post it to the list for
posterity's sake, but I leave that up to you.
You can send it to me directly as well.
Thanks,
Andy.
-----Original Message-----
From: Inca Rose [mailto:incar...@gmail.com]
Sent: Wednesday, March 25, 2009 12:09 PM
To: sofia-sip-devel Mailing List
Subject: [Sofia-sip-devel] DNS Resolving for iPhone
Hi;
I just wrote some code to make the reolver code works on the iPhone.
The iPhone is missing a resolv.conf like file, but it has a plist
files
with all the information needed.
I wrote a patch ( much like the one for win32 ) to add the DNS servers
to the system.
The patch is on the function
static sres_config_t *sres_parse_resolv_conf(sres_resolver_t *res,
char
const **options)
and it just check for a define HAVE_IPHONE_OS, if the define is true
it
call
a function to fill in the name servers.
The patch includes an obj-c file laso to deal with Foundation classes.
I dont know how to submit the patch if anyone is interested.
So, I patch config.h for HAVE_IPHONE_OS
I patch the above function and add a new file ( an obj-c m file ) to
deal with Foundation classes ( read and parse plist files ).
Regards
Inca R
------------------------------------------------------------------------
------
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
Confidentiality Notice: This e-mail message including attachments, if any, is
intended only for the person or entity to which it is addressed and may contain
confidential and/or privileged material. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply e-mail and destroy all copies of
the original message. If you are the intended recipient, but do not wish to
receive communications through this medium, please so advise the sender
immediately.
------------------------------------------------------------------------------
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel