NewLionwang / dpkt

Automatically exported from code.google.com/p/dpkt
Other
0 stars 0 forks source link

ip.IP explodes when unpacking buffer #13

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When unwrapping the results of a packet read off the wire with pcapy, ip.IP
completely explodes.

It tries to get the attribute "slice(None, 20, None)" and throws
"TypeError: getattr(): attribute name must be string".

-----

import pcapy
import dpkt.ethernet as ethernet
import dpkt.ip as ip
import dpkt.dns as dns
from optparse import OptionParser

def pcap_callback(hdr, pkt):
    frame = ethernet.Ethernet(pkt)

    packet = ip.IP(frame.data)

def main(iface):

    pcap = pcapy.open_live(iface, 0xffff, 1, 15)
    pcap.setfilter('udp port 53')

    while True:
        pcap.dispatch(-1, pcap_callback)

if __name__ == '__main__':
    op = OptionParser()
    op.add_option('-i', '--interface', dest='iface',
        default=pcapy.lookupdev(), help="Interface to listen on.")

    (opts, args) = op.parse_args()

    main(opts.iface)

-----

Traceback is:
-----

Traceback (most recent call last):
  File "dnswatch.py", line 29, in <module>
    main(opts.iface)
  File "dnswatch.py", line 20, in main
    pcap.dispatch(-1, pcap_callback)
  File "dnswatch.py", line 11, in pcap_callback
    packet = ip.IP(frame.data)
  File "/usr/local/lib/python2.5/site-packages/dpkt/dpkt.py", line 72, in
__init__
    self.unpack(args[0])
  File "/usr/local/lib/python2.5/site-packages/dpkt/ip.py", line 53, in unpack
    dpkt.Packet.unpack(self, buf)
  File "/usr/local/lib/python2.5/site-packages/dpkt/dpkt.py", line 127, in
unpack
    struct.unpack(self.__hdr_fmt__, buf[:self.__hdr_len__])):
  File "/usr/local/lib/python2.5/site-packages/dpkt/dpkt.py", line 88, in
__getitem__
    try: return getattr(self, k)
TypeError: getattr(): attribute name must be string

-----

The code's being run on Python 2.5.2 on FreeBSD 7. This occurs in the
latest version of the code checked out from SVN.

Original issue reported on code.google.com by rpije...@gmail.com on 14 Dec 2008 at 10:01

GoogleCodeExporter commented 8 years ago
Ok. So it seems that I was doing it wrong and the data attribute is magic.

Original comment by rpije...@gmail.com on 14 Dec 2008 at 10:16

GoogleCodeExporter commented 8 years ago

Original comment by jon.ober...@gmail.com on 18 Dec 2008 at 1:24