(addr, plen, laddr, loname)
return cset
Given all addresses assigned to a specific interface ('laddr' parameter),
    this function returns the "candidate set" associated with 'addr/plen'.
    
    Basically, the function filters all interface addresses to keep only those
    that have the same scope as provided prefix.
    
    This is on this list of addresses that the source selection mechanism 
    will then be performed to select the best source address associated
    with some specific destination that uses this prefix.
Given all addresses assigned to a specific interface ('laddr' parameter),
    this function returns the "candidate set" associated with 'addr/plen'.
    
    Basically, the function filters all interface addresses to keep only those
    that have the same scope as provided prefix.
    
    This is on this list of addresses that the source selection mechanism 
    will then be performed to select the best source address associated
    with some specific destination that uses this prefix.
Given all addresses assigned to a specific interface ( laddr parameter ) this function returns the candidate set associated with addr / plen . Basically the function filters all interface addresses to keep only those that have the same scope as provided prefix . This is on this list of addresses that the source selection mechanism will then be performed to select the best source address associated with some specific destination that uses this prefix .
def construct_source_candidate_set(addr, plen, laddr, loname):
    """
    Given all addresses assigned to a specific interface ('laddr' parameter),
    this function returns the "candidate set" associated with 'addr/plen'.
    
    Basically, the function filters all interface addresses to keep only those
    that have the same scope as provided prefix.
    
    This is on this list of addresses that the source selection mechanism 
    will then be performed to select the best source address associated
    with some specific destination that uses this prefix.
    """
    def cset_sort(x,y):
        x_global = 0
        if in6_isgladdr(x):
            x_global = 1
        y_global = 0
        if in6_isgladdr(y):
            y_global = 1
        res = y_global - x_global
        if res != 0 or y_global != 1:
            return res
        # two global addresses: if one is native, it wins.
        if not in6_isaddr6to4(x):
            return -1;
        return -res

    cset = []
    if in6_isgladdr(addr) or in6_isuladdr(addr):
	cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr)
    elif in6_islladdr(addr):
	cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr)
    elif in6_issladdr(addr):
	cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr)
    elif in6_ismaddr(addr):
	if in6_ismnladdr(addr):
	    cset = [('::1', 16, loname)]
	elif in6_ismgladdr(addr):
	    cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr)
	elif in6_ismlladdr(addr):
	    cset = filter(lambda x: x[1] == IPV6_ADDR_LINKLOCAL, laddr)
	elif in6_ismsladdr(addr):
	    cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr)
    elif addr == '::' and plen == 0:
	cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr)
    cset = map(lambda x: x[0], cset)
    cset.sort(cmp=cset_sort) # Sort with global addresses first
    return cset
def construct_source_candidate_set ( addr , plen , laddr , loname ) : def cset_sort ( x , y ) : x_global = 0 if in6_isgladdr ( x ) : x_global = 1 y_global = 0 if in6_isgladdr ( y ) : y_global = 1 res = y_global - x_global if res != 0 or y_global != 1 : return res # two global addresses: if one is native, it wins. if not in6_isaddr6to4 ( x ) : return - 1 return - res cset = [ ] if in6_isgladdr ( addr ) or in6_isuladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_GLOBAL , laddr ) elif in6_islladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_LINKLOCAL , laddr ) elif in6_issladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_SITELOCAL , laddr ) elif in6_ismaddr ( addr ) : if in6_ismnladdr ( addr ) : cset = [ ( '::1' , 16 , loname ) ] elif in6_ismgladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_GLOBAL , laddr ) elif in6_ismlladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_LINKLOCAL , laddr ) elif in6_ismsladdr ( addr ) : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_SITELOCAL , laddr ) elif addr == '::' and plen == 0 : cset = filter ( lambda x : x [ 1 ] == IPV6_ADDR_GLOBAL , laddr ) cset = map ( lambda x : x [ 0 ] , cset ) cset . sort ( cmp = cset_sort ) # Sort with global addresses first return cset