~free.ekanayaka/landscape-client/socket-locks-fix

« back to all changes in this revision

Viewing changes to landscape/lib/network.py

Merge duplicate-network-interfaces [r=bigkevmcd,jkakar] [f=597000]

Filter duplicate network interfaces in get_active_interfaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    """
49
49
    max_interfaces = 128
50
50
 
51
 
    # setup an an array to hold our response, and initialized to null strings.
 
51
    # Setup an an array to hold our response, and initialized to null strings.
52
52
    interfaces = array.array("B", "\0" * max_interfaces * IF_STRUCT_SIZE)
53
53
    buffer_size = interfaces.buffer_info()[0]
54
54
    packed_bytes = struct.pack(
59
59
 
60
60
    result = interfaces.tostring()
61
61
 
62
 
    # generator over the interface names
 
62
    # Generator over the interface names
 
63
    already_found = set()
63
64
    for index in range(0, byte_length, IF_STRUCT_SIZE):
64
65
        ifreq_struct = result[index:index+IF_STRUCT_SIZE]
65
66
        interface_name = ifreq_struct[:ifreq_struct.index("\0")]
66
 
        yield interface_name
 
67
        if interface_name not in already_found:
 
68
            already_found.add(interface_name)
 
69
            yield interface_name
67
70
 
68
71
 
69
72
def get_broadcast_address(sock, interface):