# Buggy code
def ParseDNS(dns_packet_data):
    """Parse DNS packets and return a string with relevant details.

    Args:
      dns_packet_data: DNS packet data.

    Returns:
      Formatted DNS details.
    """
    dns_data = []

    try:
        dns = dpkt.dns.DNS(dns_packet_data)
        if dns.rcode is dpkt.dns.DNS_RCODE_NOERR:
            if dns.get_qr() == 1:
                if not dns.an:
                    dns_data.append("DNS Response: No answer for ")
                    dns_data.append(dns.qd[0].name)
                else:
                    # Type of DNS answer.
                    for answer in dns.an:
                        if answer.type == 5:
                            dns_data.append("DNS-CNAME request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(answer.cname)
                        elif answer.type == 1:
                            dns_data.append("DNS-A request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(socket.inet_ntoa(answer.rdata))
                        elif answer.type == 12:
                            dns_data.append("DNS-PTR request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(answer.ptrname)
            elif not dns.get_qr():
                dns_data.append("DNS Query for ")
                dns_data.append(dns.qd[0].name)
        else:
            dns_data.append("DNS error code ")
            dns_data.append(str(dns.rcode))

    except dpkt.UnpackError as exception:
        dns_data.append(
            "DNS Unpack Error: {0:s}. First 20 of data {1:s}".format(
                exception, repr(dns_packet_data[:20])
            )
        )
    except IndexError as exception:
        dns_data.append("DNS Index Error: {0:s}".format(exception))

    return " ".join(dns_data)


# Traceback (ValueError)
2015-10-06 10:24:11,042 [ERROR] (MainProcess) PID:1607 <worker> Unknown format code 'd' for object of type 'float'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/engine/worker.py", line 471, in _ProcessPathSpec
self._ProcessFileEntry(file_entry)
File "/usr/lib/python2.7/dist-packages/plaso/engine/worker.py", line 430, in _ProcessFileEntry
self._ParseFileEntryWithParser(parser_object, file_entry)
File "/usr/lib/python2.7/dist-packages/plaso/engine/worker.py", line 213, in _ParseFileEntryWithParser
parser_object.UpdateChainAndParse(self._parser_mediator)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/interface.py", line 72, in UpdateChainAndParse
self.Parse(parser_mediator, **kwargs)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/interface.py", line 256, in Parse
self.ParseFileObject(parser_mediator, file_object, **kwargs)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/pcap.py", line 762, in ParseFileObject
len(ethernet_frame), ethernet_frame.data)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/pcap.py", line 550, in _ParseIPPacket
timestamp, source_ip_address, destination_ip_address)
ValueError: Unknown format code 'd' for object of type 'float'
Processing completed.

# Fixed code
def ParseDNS(dns_packet_data):
    """Parse DNS packets and return a string with relevant details.

    Args:
      dns_packet_data: DNS packet data.

    Returns:
      Formatted DNS details.
    """
    dns_data = []

    try:
        dns = dpkt.dns.DNS(dns_packet_data)
        if dns.rcode is dpkt.dns.DNS_RCODE_NOERR:
            if dns.qr == 1:
                if not dns.an:
                    dns_data.append("DNS Response: No answer for ")
                    dns_data.append(dns.qd[0].name)
                else:
                    # Type of DNS answer.
                    for answer in dns.an:
                        if answer.type == 5:
                            dns_data.append("DNS-CNAME request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(answer.cname)
                        elif answer.type == 1:
                            dns_data.append("DNS-A request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(socket.inet_ntoa(answer.rdata))
                        elif answer.type == 12:
                            dns_data.append("DNS-PTR request ")
                            dns_data.append(answer.name)
                            dns_data.append(" response: ")
                            dns_data.append(answer.ptrname)
            elif not dns.qr:
                dns_data.append("DNS Query for ")
                dns_data.append(dns.qd[0].name)
        else:
            dns_data.append("DNS error code ")
            dns_data.append(str(dns.rcode))

    except dpkt.UnpackError as exception:
        dns_data.append(
            "DNS Unpack Error: {0:s}. First 20 of data {1:s}".format(
                exception, repr(dns_packet_data[:20])
            )
        )
    except IndexError as exception:
        dns_data.append("DNS Index Error: {0:s}".format(exception))

    return " ".join(dns_data)