def get_all_field_names(packet, layer=None):
    """
        Builds a unique list of field names, that exist in the packet,
        for the specified layer.

        If no layer is provided, all layers are considered.

        Args:
            packet: the pyshark packet object the fields will be gathered from
            layer: the string name of the layer that will be targeted

        Returns:
            a set containing all unique field names
            or None, if packet is None
    """
    if not packet:
        return None
    field_names = set()
    for current_layer in packet.layers:
        if not layer or layer == current_layer.__dict__['_layer_name']:
            for field in current_layer.__dict__['_all_fields']:
                field_names.add(field)
    return field_names
