コード例 #1
0
ファイル: jdns_sys.c プロジェクト: ftkalcevic/QtQuickVcp
static jdns_string_t *reg_readString(HKEY hk, const char *subkey)
{
	char *buf;
	DWORD bufsize;
	int ret;
	jdns_string_t *str = 0;

	bufsize = 1024;
	buf = (char *)jdns_alloc((int)bufsize);
	if(!buf)
		return 0;
	ret = RegQueryValueExA(hk, subkey, 0, 0, (LPBYTE)buf, &bufsize);
	if(ret == ERROR_MORE_DATA)
	{
		buf = (char *)jdns_realloc(buf, bufsize);
		if(!buf)
		{
			jdns_free(buf);
			return 0;
		}
		ret = RegQueryValueExA(hk, subkey, 0, 0, (LPBYTE)buf, &bufsize);
	}
	if(ret == ERROR_SUCCESS)
	{
		str = jdns_string_new();
		jdns_string_set_cstr(str, (char *)buf);
	}
	jdns_free(buf);
	return str;
}
コード例 #2
0
ファイル: jdns_sys.c プロジェクト: ftkalcevic/QtQuickVcp
static jdns_dnsparams_t *dnsparams_get_winsys()
{
	jdns_dnsparams_t *params;
	GetNetworkParamsFunc myGetNetworkParams;
	DWORD ret;
	HINSTANCE lib;
	jdns_address_t *addr;
	jdns_string_t *str;
	IP_ADDR_STRING *ipstr;

	lib = LoadLibraryA("iphlpapi");
	if(!lib)
		return 0;

	params = 0;
	myGetNetworkParams = (GetNetworkParamsFunc)GetProcAddress(lib, "GetNetworkParams");
	if(myGetNetworkParams)
	{
		ULONG bufsize = 0;
		ret = myGetNetworkParams(0, &bufsize);
		if(ret == ERROR_BUFFER_OVERFLOW)
		{
			FIXED_INFO *info = (FIXED_INFO *)jdns_alloc((int)bufsize);
			ret = myGetNetworkParams(info, &bufsize);
			if(ret == ERROR_SUCCESS)
			{
				params = jdns_dnsparams_new();
				ipstr = &info->DnsServerList;
				while(ipstr)
				{
					addr = jdns_address_new();
					if(jdns_address_set_cstr(addr, (char *)ipstr->IpAddress.String))
						jdns_dnsparams_append_nameserver(params, addr, JDNS_UNICAST_PORT);
					jdns_address_delete(addr);
					ipstr = ipstr->Next;
				}
				str = jdns_string_new();
				jdns_string_set_cstr(str, info->DomainName);
				if(str->size > 0)
					jdns_dnsparams_append_domain(params, str);
				jdns_string_delete(str);
			}
			jdns_free(info);
		}
	}
	FreeLibrary(lib);
	return params;
}
コード例 #3
0
ファイル: jdns_sys.c プロジェクト: ftkalcevic/QtQuickVcp
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;
}
コード例 #4
0
ファイル: jdns_sys.c プロジェクト: ftkalcevic/QtQuickVcp
static jdns_string_t *string_simplify(const jdns_string_t *in)
{
	int n;
	int pos;
	int total;
	unsigned char *out;
	int outlen;
	jdns_string_t *outstr;
	jdns_stringlist_t *wordlist;

	// gather words and total of lengths
	pos = 0;
	total = 0;
	wordlist = jdns_stringlist_new();
	while(1)
	{
		jdns_string_t *word;
		unsigned char *str = string_getnextword(in->data, in->size, pos, &pos);
		if(!str)
			break;
		word = jdns_string_new();
		jdns_string_set_cstr(word, (char *)str);
		jdns_free(str);
		jdns_stringlist_append(wordlist, word);
		total += word->size;
		jdns_string_delete(word);
	}

	if(total == 0)
	{
		jdns_stringlist_delete(wordlist);

		outstr = jdns_string_new();
		jdns_string_set_cstr(outstr, "");
		return outstr;
	}

	// we need to allocate space for total lengths and wordcount-1 spaces
	outlen = total + (wordlist->count - 1);
	out = (unsigned char *)jdns_alloc(outlen);

	// lay out the words
	pos = 0;
	for(n = 0; n < wordlist->count; ++n)
	{
		unsigned char *data = wordlist->item[n]->data;
		int size = wordlist->item[n]->size;
		memcpy(out + pos, data, size);
		pos += size;

		// if this is not the last word, append a space
		if(n + 1 < wordlist->count)
			out[pos++] = ' ';
	}
	jdns_stringlist_delete(wordlist);

	outstr = jdns_string_new();
	jdns_string_set(outstr, out, outlen);
	jdns_free(out);
	return outstr;
}
コード例 #5
0
ファイル: jdns_sys.c プロジェクト: LittleForker/tomahawk
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;
}