Example #1
0
// SearchBest searches radix tree to find a matching node using usual subnetting rules
// for the address specified. If no mask width is specified, the longest possible mask
// for this type of address (IPv4 or IPv6) is assumed.
// Returns triple in which the first element indicates success of a search,
// the second element returns user payload (or empty string if not found)
// and the third element returns error object in case such an error occured or nil otherwise.
func (rtree *NetRadixTree) SearchBest(addr string) (found bool, udata string, err error) {
	var prefix C.prefix_t
	e := rtree.fillPrefix(&prefix, addr)
	if e != nil {
		return false, "", e
	}

	node := C.radix_search_best(rtree.tree, &prefix)
	if node != nil {
		return true, C.GoString((*C.char)(node.data)), nil
	}

	return false, "", nil
}
Example #2
0
// SearchBest searches radix tree to find a matching node using usual subnetting rules
// for the address specified. If no mask width is specified, the longest possible mask
// for this type of address (IPv4 or IPv6) is assumed.
// Returns triple in which the first element indicates success of a search,
// the second element returns user payload (or empty string if not found)
// and the third element returns error object in case such an error occured or nil otherwise.
func (rtree *NetRadixTree) SearchBest(addr string) (found bool, udata unsafe.Pointer, err error) {
	var prefix C.prefix_t
	e := rtree.fillPrefix(&prefix, addr)
	if e != nil {
		return false, nil, e
	}

	node := C.radix_search_best(rtree.tree, &prefix)
	if node != nil {
		return true, node.data, nil
	}

	return false, nil, nil
}