https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L357.

    Also https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L338

def nl_socket_get_local_port(sk):
    """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L357.

    Also https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L338
    """
    if not sk.s_local.nl_pid:
        port = generate_local_port()
        sk.s_flags &= ~NL_OWN_PORT
        sk.s_local.nl_pid = port
        return port
    return sk.s_local.nl_pid