Beispiel #1
0
static jdns_dnsparams_t *dnsparams_get_unixsys()
{
	int n;
	jdns_dnsparams_t *params;

#ifdef JDNS_MODERN_RES_API
	struct __res_state res;
	memset(&res, 0, sizeof(struct __res_state));
	n = res_ninit(&res);
#define RESVAR res
#else
	n = my_res_init();
#define RESVAR _res
#endif

	params = jdns_dnsparams_new();

	// error initializing?
	if(n == -1)
		return params;

#ifdef USE_INDEP_EXT
	for(n = 0; n < MAXNS && n < RESVAR.nscount; ++n)
	{
		struct sockaddr_in *sa = (struct sockaddr_in*)&(_res_ext.nsaddr_list[n]);
		jdns_address_t *addr = jdns_address_new();
		if (sa->sin_family = AF_INET6) {
			struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
			jdns_address_set_ipv6(addr, sa6->sin6_addr.s6_addr);
		} else {
			jdns_address_set_ipv4(addr, ntohl(sa->sin_addr.s_addr));
		}
		jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
		jdns_address_delete(addr);
	}
#else
	// nameservers - ipv6
#ifdef __GLIBC__
	for(n = 0; n < MAXNS; ++n)
#else
	for(n = 0; n < MAXNS && n < RESVAR._u._ext.nscount; ++n)
#endif
	{
		jdns_address_t *addr;
		struct sockaddr_in6 *sa6;

#ifdef USE_EXTEXT
		// seems _ext.ext can be null in some cases...
		if(RESVAR._u._ext.ext == NULL)
			break;

		sa6 = ((struct sockaddr_in6 *)RESVAR._u._ext.ext) + n;
#else
		sa6 = RESVAR._u._ext.nsaddrs[n];
#endif

		if(sa6 == NULL)
			continue;
		addr = jdns_address_new();
		jdns_address_set_ipv6(addr, sa6->sin6_addr.s6_addr);
		jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
		jdns_address_delete(addr);
	}

	// nameservers - ipv4
#ifdef __GLIBC__
	int ns4count = RESVAR.nscount - RESVAR._u._ext.nscount6;
	for(n = 0; n < MAXNS && n < ns4count; ++n)
#else
	for(n = 0; n < MAXNS && n < RESVAR.nscount; ++n)
#endif
	{
		jdns_address_t *addr = jdns_address_new();
		jdns_address_set_ipv4(addr, ntohl(RESVAR.nsaddr_list[n].sin_addr.s_addr));
		jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
		jdns_address_delete(addr);
	}
#endif

	// domain name
	if(strlen(RESVAR.defdname) > 0)
	{
		jdns_string_t *str;
		jdns_string_t *p;
		str = jdns_string_new();
		jdns_string_set_cstr(str, RESVAR.defdname);
		p = string_tolower(str);
		jdns_string_delete(str);
		str = p;
		jdns_dnsparams_append_domain(params, str);
		jdns_string_delete(str);
	}

	// search list
#ifdef MAXDFLSRCH
	for(n = 0; n < MAXDFLSRCH && RESVAR.dnsrch[n]; ++n)
	{
		if(strlen(RESVAR.dnsrch[n]) > 0)
		{
			jdns_string_t *str;
			jdns_string_t *p;
			str = jdns_string_new();
			jdns_string_set_cstr(str, RESVAR.dnsrch[n]);
			p = string_tolower(str);
			jdns_string_delete(str);
			str = p;

			// don't add dups
			if(!dnsparams_have_domain(params, str))
				jdns_dnsparams_append_domain(params, str);

			jdns_string_delete(str);
		}
	}
#endif

	return params;
}
Beispiel #2
0
static jdns_dnsparams_t *dnsparams_get_unixsys()
{
	int n;
	jdns_dnsparams_t *params;

#ifdef JDNS_MODERN_RES_API
	struct __res_state res;
	memset(&res, 0, sizeof(struct __res_state));
	n = res_ninit(&res);
#define RESVAR res
#else
	n = my_res_init();
#define RESVAR _res
#endif

	params = jdns_dnsparams_new();

	// error initializing?
	if(n == -1)
		return params;

	// nameservers - ipv6
	for(n = 0; n < MAXNS && n < RESVAR._u._ext.nscount; ++n)
	{
		jdns_address_t *addr;
		struct sockaddr_in6 *sa6;

#ifdef USE_EXTEXT
		sa6 = ((struct sockaddr_in6 *)RESVAR._u._ext.ext) + n;
#else
		sa6 = RESVAR._u._ext.nsaddrs[n];
#endif

		if(sa6 == NULL)
			continue;
		addr = jdns_address_new();
		jdns_address_set_ipv6(addr, sa6->sin6_addr.s6_addr);
		jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
		jdns_address_delete(addr);
	}

	// nameservers - ipv4
	for(n = 0; n < MAXNS && n < RESVAR.nscount; ++n)
	{
		jdns_address_t *addr = jdns_address_new();
		jdns_address_set_ipv4(addr, ntohl(RESVAR.nsaddr_list[n].sin_addr.s_addr));
		jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
		jdns_address_delete(addr);
	}

	// domain name
	if(strlen(RESVAR.defdname) > 0)
	{
		jdns_string_t *str;
		jdns_string_t *p;
		str = jdns_string_new();
		jdns_string_set_cstr(str, RESVAR.defdname);
		p = string_tolower(str);
		jdns_string_delete(str);
		str = p;
		jdns_dnsparams_append_domain(params, str);
		jdns_string_delete(str);
	}

	// search list
#ifdef MAXDFLSRCH
	for(n = 0; n < MAXDFLSRCH && RESVAR.dnsrch[n]; ++n)
	{
		if(strlen(RESVAR.dnsrch[n]) > 0)
		{
			jdns_string_t *str;
			jdns_string_t *p;
			str = jdns_string_new();
			jdns_string_set_cstr(str, RESVAR.dnsrch[n]);
			p = string_tolower(str);
			jdns_string_delete(str);
			str = p;

			// don't add dups
			if(!dnsparams_have_domain(params, str))
				jdns_dnsparams_append_domain(params, str);

			jdns_string_delete(str);
		}
	}
#endif

	return params;
}