def format_scapy_packet(packet):
    fields = []
    for f in packet.fields_desc:
        if (f.name in packet.fields):
            val = f.i2repr(packet, packet.fields[f.name])
        elif (f.name in packet.overloaded_fields):
            val = f.i2repr(packet, packet.overloaded_fields[f.name])
        else:
            continue
        fields.append('{0}={1}'.format(col256(f.name, '542'), col256(val, '352')))
    (yield '{0} {1}'.format(col256(packet.__class__.__name__, '501'), ' '.join(fields)))
    if packet.payload:
        if isinstance(packet.payload, scapy.packet.Raw):
            raw_data = str(packet.payload)
            for line in make_printable(raw_data).splitlines():
                (yield ('    ' + line))
        elif isinstance(packet.payload, scapy.packet.Packet):
            for line in format_scapy_packet(packet.payload):
                (yield ('    ' + line))
        else:
            for line in repr(packet.payload).splitlines():
                (yield ('    ' + line))
def format_scapy_packet(packet):
    fields = []
    for f in packet.fields_desc:
        if (f.name in packet.fields):
            val = f.i2repr(packet, packet.fields[f.name])
        elif (f.name in packet.overloaded_fields):
            val = f.i2repr(packet, packet.overloaded_fields[f.name])
        else:
            continue
        fields.append('{0}={1}'.format(col256(f.name, '542'), col256(val, '352')))
    (yield '{0} {1}'.format(col256(packet.__class__.__name__, '501'), ' '.join(fields)))
    if packet.payload:
        if isinstance(packet.payload, scapy.packet.Raw):
            raw_data = str(packet.payload)
            for line in make_printable(raw_data).splitlines():
                (yield ('    ' + line))
        elif isinstance(packet.payload, scapy.packet.Packet):
            for line in format_scapy_packet(packet.payload):
                (yield ('    ' + line))
        else:
            for line in repr(packet.payload).splitlines():
                (yield ('    ' + line))