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

Update Packet __iter__() method #21

Closed
NazarTkachuk opened this issue Mar 2, 2017 · 1 comment
Closed

Update Packet __iter__() method #21

NazarTkachuk opened this issue Mar 2, 2017 · 1 comment

Comments

@NazarTkachuk
Copy link
Contributor

Iteration over every layer starting with lowest layer doesn't work. All time first layer is skipped because _get_bodyhandler() method returns next layer for lowest layer as well.

pkt = ethernet.Ethernet()+ip.IP()+tcp.TCP()
for p in pkt.lowest_layer:
... print(p)
...
IP(v_hl=45, tos=0, len=28, id=0, off=0, ttl=40, p=6, sum=7AD1, src=b'\x00\x00\x00\x00', dst=b'\x00\x00\x00\x00', opts=[], handler=tcp)
TCP(sport=DEAD, dport=0, seq=DEADBEEF, ack=0, off_x2=50, flags=2, win=FFFF, sum=3398, urp=0, opts=[], bytes=b'')

I created pull request with proposal to start iterate from first layer all time. It makes iteration more flexible.
To skip first layer use upper layer or body handler. See examples below

  1. Iterate over every layer

pkt = ethernet.Ethernet()+ip.IP()+tcp.TCP()
for p in pkt:
... print(p)
...
Ethernet(dst=b'\xff\xff\xff\xff\xff\xff', src=b'\xff\xff\xff\xff\xff\xff', vlan=[], type=800, handler=ip)
IP(v_hl=45, tos=0, len=28, id=0, off=0, ttl=40, p=6, sum=7AD1, src=b'\x00\x00\x00\x00', dst=b'\x00\x00\x00\x00', opts=[], handler=tcp)
TCP(sport=DEAD, dport=0, seq=DEADBEEF, ack=0, off_x2=50, flags=2, win=FFFF, sum=3398, urp=0, opts=[], bytes=b'')

  1. Skip first layer

for p in pkt.upper_layer:
... print(p)
...
IP(v_hl=45, tos=0, len=28, id=0, off=0, ttl=40, p=6, sum=7AD1, src=b'\x00\x00\x00\x00', dst=b'\x00\x00\x00\x00', opts=[], handler=tcp)
TCP(sport=DEAD, dport=0, seq=DEADBEEF, ack=0, off_x2=50, flags=2, win=FFFF, sum=3398, urp=0, opts=[], bytes=b'')

  1. Start from highest

for p in pkt.highest_layer:
... print(p)
...
TCP(sport=DEAD, dport=0, seq=DEADBEEF, ack=0, off_x2=50, flags=2, win=FFFF, sum=3398, urp=0, opts=[], bytes=b'')

Thanks,
Nazar

@mike01
Copy link
Owner

mike01 commented Mar 3, 2017

Thanks, pull request got merged

@mike01 mike01 closed this as completed Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants