Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ip.IP explodes when unpacking buffer #13

Closed
GoogleCodeExporter opened this issue May 5, 2015 · 2 comments
Closed

ip.IP explodes when unpacking buffer #13

GoogleCodeExporter opened this issue May 5, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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

  • Changed state: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant