forked from kbandla/dpkt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kiran Bandla
committed
Sep 10, 2013
1 parent
7503ee6
commit 383cdbf
Showing
12 changed files
with
650 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include AUTHORS CHANGES README LICENSE HACKING | ||
recursive-include examples * | ||
recursive-include tests * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# $Id: __init__.py 82 2011-01-10 03:43:38Z timur.alperovich@gmail.com $ | ||
# $Id: __init__.py 89 2013-05-23 01:31:22Z andrewflnr@gmail.com $ | ||
|
||
"""fast, simple packet creation and parsing.""" | ||
|
||
__author__ = 'Dug Song <[email protected]>' | ||
__copyright__ = 'Copyright (c) 2004 Dug Song' | ||
__license__ = 'BSD' | ||
__url__ = 'http://dpkt.googlecode.com/' | ||
__version__ = '1.7' | ||
__version__ = '1.8' | ||
|
||
from dpkt import * | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# $Id: http.py 80 2011-01-06 16:50:42Z jon.oberheide $ | ||
# $Id: http.py 86 2013-03-05 19:25:19Z [email protected] $ | ||
|
||
"""Hypertext Transfer Protocol.""" | ||
|
||
|
@@ -193,9 +193,13 @@ def test_format_request(self): | |
r.headers['content-type'] = 'text/plain' | ||
r.headers['content-length'] = '5' | ||
r.body = 'hello' | ||
assert str(r) == 'POST /foo/bar/baz.html HTTP/1.0\r\ncontent-length: 5\r\ncontent-type: text/plain\r\n\r\nhello' | ||
s = str(r) | ||
assert s.startswith('POST /foo/bar/baz.html HTTP/1.0\r\n') | ||
assert s.endswith('\r\n\r\nhello') | ||
assert '\r\ncontent-length: 5\r\n' in s | ||
assert '\r\ncontent-type: text/plain\r\n' in s | ||
r = Request(str(r)) | ||
assert str(r) == 'POST /foo/bar/baz.html HTTP/1.0\r\ncontent-length: 5\r\ncontent-type: text/plain\r\n\r\nhello' | ||
assert str(r) == s | ||
|
||
def test_chunked_response(self): | ||
s = """HTTP/1.1 200 OK\r\nCache-control: no-cache\r\nPragma: no-cache\r\nContent-Type: text/javascript; charset=utf-8\r\nContent-Encoding: gzip\r\nTransfer-Encoding: chunked\r\nSet-Cookie: S=gmail=agg:gmail_yj=v2s:gmproxy=JkU; Domain=.google.com; Path=/\r\nServer: GFE/1.3\r\nDate: Mon, 12 Dec 2005 22:33:23 GMT\r\n\r\na\r\n\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00\r\n152\r\nm\x91MO\xc4 \x10\x86\xef\xfe\n\x82\xc9\x9eXJK\xe9\xb6\xee\xc1\xe8\x1e6\x9e4\xf1\xe0a5\x86R\xda\x12Yh\x80\xba\xfa\xef\x85\xee\x1a/\xf21\x99\x0c\xef0<\xc3\x81\xa0\xc3\x01\xe6\x10\xc1<\xa7eYT5\xa1\xa4\xac\xe1\xdb\x15:\xa4\x9d\x0c\xfa5K\x00\xf6.\xaa\xeb\x86\xd5y\xcdHY\x954\x8e\xbc*h\x8c\x8e!L7Y\xe6\'\xeb\x82WZ\xcf>8\x1ed\x87\x851X\xd8c\xe6\xbc\x17Z\x89\x8f\xac \x84e\xde\n!]\x96\x17i\xb5\x02{{\xc2z0\x1e\x0f#7\x9cw3v\x992\x9d\xfc\xc2c8\xea[/EP\xd6\xbc\xce\x84\xd0\xce\xab\xf7`\'\x1f\xacS\xd2\xc7\xd2\xfb\x94\x02N\xdc\x04\x0f\xee\xba\x19X\x03TtW\xd7\xb4\xd9\x92\n\xbcX\xa7;\xb0\x9b\'\x10$?F\xfd\xf3CzPt\x8aU\xef\xb8\xc8\x8b-\x18\xed\xec<\xe0\x83\x85\x08!\xf8"[\xb0\xd3j\x82h\x93\xb8\xcf\xd8\x9b\xba\xda\xd0\x92\x14\xa4a\rc\reM\xfd\x87=X;h\xd9j;\xe0db\x17\xc2\x02\xbd\xb0F\xc2in#\xfb:\xb6\xc4x\x15\xd6\x9f\x8a\xaf\xcf)\x0b^\xbc\xe7i\x11\x80\x8b\x00D\x01\xd8/\x82x\xf6\xd8\xf7J(\xae/\x11p\x1f+\xc4p\t:\xfe\xfd\xdf\xa3Y\xfa\xae4\x7f\x00\xc5\xa5\x95\xa1\xe2\x01\x00\x00\r\n0\r\n\r\n""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# $Id: ip.py 65 2010-03-26 02:53:51Z dugsong $ | ||
# $Id: ip.py 87 2013-03-05 19:41:04Z [email protected] $ | ||
|
||
"""Internet Protocol.""" | ||
|
||
|
@@ -55,7 +55,10 @@ def unpack(self, buf): | |
if ol < 0: | ||
raise dpkt.UnpackError, 'invalid header length' | ||
self.opts = buf[self.__hdr_len__:self.__hdr_len__ + ol] | ||
buf = buf[self.__hdr_len__ + ol:self.len] | ||
if self.len: | ||
buf = buf[self.__hdr_len__ + ol:self.len] | ||
else: # very likely due to TCP segmentation offload | ||
buf = buf[self.__hdr_len__ + ol:] | ||
try: | ||
self.data = self._protosw[self.p](buf) | ||
setattr(self, self.data.__class__.__name__.lower(), self.data) | ||
|
@@ -285,6 +288,14 @@ def test_opt(self): | |
s = '\x4f\x00\x00\x50\xae\x08\x00\x00\x40\x06\x17\xfc\xc0\xa8\x0a\x26\xc0\xa8\x0a\x01\x07\x27\x08\x01\x02\x03\x04\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | ||
ip = IP(s) | ||
ip.sum = 0 | ||
self.failUnless(str(ip) == s) | ||
self.failUnless(str(ip) == s) | ||
|
||
def test_zerolen(self): | ||
import tcp | ||
d = 'X' * 2048 | ||
s = 'E\x00\x00\x004\xce@\x00\x80\x06\x00\x00\x7f\x00\x00\x01\x7f\x00\x00\x01\xccN\x0c8`\xff\xc6N_\x8a\x12\x98P\x18@):\xa3\x00\x00' + d | ||
ip = IP(s) | ||
self.failUnless(isinstance(ip.data, tcp.TCP)) | ||
self.failUnless(ip.tcp.data == d) | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# $Id: ip6.py 58 2010-03-06 00:06:14Z dugsong $ | ||
# $Id: ip6.py 87 2013-03-05 19:41:04Z [email protected] $ | ||
|
||
"""Internet Protocol, version 6.""" | ||
|
||
|
@@ -13,7 +13,11 @@ class IP6(dpkt.Packet): | |
('src', '16s', ''), | ||
('dst', '16s', '') | ||
) | ||
_protosw = {} # XXX - shared with IP | ||
|
||
# XXX - to be shared with IP. We cannot refer to the ip module | ||
# right now because ip.__load_protos() expects the IP6 class to be | ||
# defined. | ||
_protosw = None | ||
|
||
def _get_v(self): | ||
return self.v_fc_flow >> 28 | ||
|
@@ -37,7 +41,10 @@ def unpack(self, buf): | |
dpkt.Packet.unpack(self, buf) | ||
self.extension_hdrs = dict(((i, None) for i in ext_hdrs)) | ||
|
||
buf = self.data[:self.plen] | ||
if self.plen: | ||
buf = self.data[:self.plen] | ||
else: # due to jumbo payload or TSO | ||
buf = self.data | ||
|
||
next = self.nxt | ||
|
||
|
@@ -91,9 +98,14 @@ def get_proto(cls, p): | |
return cls._protosw[p] | ||
get_proto = classmethod(get_proto) | ||
|
||
# XXX - auto-load IP6 dispatch table from IP dispatch table | ||
import ip | ||
IP6._protosw.update(ip.IP._protosw) | ||
# We are most likely still in the middle of ip.__load_protos() which | ||
# implicitly loads this module through __import__(), so the content of | ||
# ip.IP._protosw is still incomplete at the moment. By sharing the | ||
# same dictionary by reference as opposed to making a copy, when | ||
# ip.__load_protos() finishes, we will also automatically get the most | ||
# up-to-date dictionary. | ||
IP6._protosw = ip.IP._protosw | ||
|
||
class IP6ExtensionHeader(dpkt.Packet): | ||
""" | ||
|
Oops, something went wrong.