Beispiel #1
0
/* You should meke sure there is no additional record and nameserver record */
void DNSExpandCName(const char *DNSBody)
{
	int				AnswerCount	=	DNSGetAnswerCount(DNSBody);
	int				Itr	=	1;
	const char		*Answer;
	DNSRecordType	Type;
	char			*Resource;
	int				ResourceLength;

	int				NameLength;
	char			*NameEnd; /* After terminated-zero */

	char			*DNSEnd;


	if( AnswerCount < 1 )
	{
		return;
	}

	do
	{
		Answer = DNSGetAnswerRecordPosition(DNSBody, Itr);

		Type = DNSGetRecordType(Answer);
		if( Type == DNS_TYPE_CNAME )
		{
			ResourceLength = DNSGetResourceDataLength(Answer);
			Resource = (char *)DNSGetResourceDataPos(Answer);
			NameLength = DNSGetHostNameLength(DNSBody, Resource);

			NameEnd = Resource + ResourceLength;

			DNSEnd = (char *)DNSGetAnswerRecordPosition(DNSBody, AnswerCount + 1);

			SET_16_BIT_U_INT(Resource - 2, NameLength + 1);

			memmove(Resource + NameLength + 1, NameEnd, DNSEnd - NameEnd);

			DNSCopyLable(DNSBody, Resource, Resource);
		}

		++Itr;

	}while( Itr <= AnswerCount );
}
Beispiel #2
0
int IPv6AddressToNum(const char *asc, void *Buffer)
{
	_16BIT_INT	*buf_s	=	(_16BIT_INT *)Buffer;
	const char	*itr;

	memset(Buffer, 0, 16);

	for(; isspace(*asc); ++asc);

	if( strstr(asc, "::") == NULL )
	{	/* full format */
		int a[8];
		sscanf(asc, "%x:%x:%x:%x:%x:%x:%x:%x",
				a, a + 1, a + 2, a + 3, a + 4, a + 5, a + 6, a + 7
				);
		SET_16_BIT_U_INT(buf_s, a[0]);
		SET_16_BIT_U_INT(buf_s + 1, a[1]);
		SET_16_BIT_U_INT(buf_s + 2, a[2]);
		SET_16_BIT_U_INT(buf_s + 3, a[3]);
		SET_16_BIT_U_INT(buf_s + 4, a[4]);
		SET_16_BIT_U_INT(buf_s + 5, a[5]);
		SET_16_BIT_U_INT(buf_s + 6, a[6]);
		SET_16_BIT_U_INT(buf_s + 7, a[7]);
	} else {
		/* not full*/

		if( asc[2] == '\0' || isspace(asc[2]) )
		{
			memset(Buffer, 0, 16);
			return 0;
		}

		while(1)
		{
			int a;
			itr = asc;
			asc = strchr(asc, ':');
			if( asc == NULL )
				return 0;

			if( itr == asc )
			{
				break;
			}

			sscanf(itr, "%x:", &a);
			SET_16_BIT_U_INT(buf_s, a);
			++buf_s;
			++asc;
		}
		buf_s = (_16BIT_INT *)Buffer + 7;
		for(; *asc != '\0'; ++asc);
		while(1)
		{
			int a;
			for(itr = asc; *itr != ':'; --itr);

			if( *(itr + 1) == '\0' )
				break;

			sscanf(itr + 1, "%x", &a);
			SET_16_BIT_U_INT(buf_s, a);
			--buf_s;
			asc = itr - 1;

			if( *(itr - 1) == ':' )
				break;
		}
	}
	return 0;
}