[SR-Users] sip-router config file syntax question

Iñaki Baz Castillo ibc at aliax.net
Tue Jun 15 21:21:30 CEST 2010


2010/6/15 Klaus Darilion <klaus.mailinglists at pernau.at>:
> What about IPv6 addresses?

IPv6 addresses must me converted to in6_addr struct prior to match
them, as there can be different representations for the same IPv6
address.

For example, take a look to this code:


/**
 * Convert an IPv6 address as hexadecimal without ":" separator (32 characters)
 * into in6_addr structure.
 *
 * \return Returns 0 on failure, or 1 on error.
 */
int hex2ipv6(const char *text, struct in6_addr *ip)
{
#ifdef LINUX
#  define READ(text, index) sscanf((text), "%08" SCNx32, (uint32_t *)
&ip->s6_addr32[index])
#else
#  define READ(text, index) sscanf((text), "%08" SCNx32, (uint32_t *)
&ip->__u6_addr.__u6_addr32[index])
#endif
	/* Copy text */
	char copy[33];
	if (strlen(text) != 32)
		return 0;
	SECURE_STRNCPY(copy, text, sizeof(copy));

	if (READ(copy + 8 * 3, 3) != 1)
		return 0;
	copy[8 * 3] = 0;

	if (READ(copy + 8 * 2, 2) != 1)
		return 0;
	copy[8 * 2] = 0;

	if (READ(copy + 8 * 1, 1) != 1)
		return 0;
	copy[8] = 0;

	if (READ(copy + 8 * 0, 0) != 1)
		return 0;
	return 1;
#undef READ
}

/**
 * Compare two IPv6 addresses.
 *
 * \return 1 on equality, 0 otherwise.
 */
int ipv6_equal(const struct in6_addr *ipa, const struct in6_addr *ipb)
{
	return memcmp(ipa, ipb, sizeof(struct in6_addr)) == 0;
}




Extracted from here:
  http://software.inl.fr/trac/browser/mirror/edenwall/nufw/trunk/nufw/src/libs/nubase/ipv6.c?rev=9107

-- 
Iñaki Baz Castillo
<ibc at aliax.net>



More information about the sr-users mailing list