summaryrefslogtreecommitdiff
path: root/external/construct/protocols/layer4/udp.py
diff options
context:
space:
mode:
authorLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
committerLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
commit9a13903a2f7d3a65fdf15a65fb59cccd622e2066 (patch)
tree9403b7dff39eb5e5d7fa0f79efb69b496add4c4b /external/construct/protocols/layer4/udp.py
parent11cc316b74d5f3f283413a33e7693b314741aa4a (diff)
downloadmanachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.gz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.bz2
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.xz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.zip
Initial commit
Diffstat (limited to 'external/construct/protocols/layer4/udp.py')
-rw-r--r--external/construct/protocols/layer4/udp.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/external/construct/protocols/layer4/udp.py b/external/construct/protocols/layer4/udp.py
new file mode 100644
index 0000000..42a951e
--- /dev/null
+++ b/external/construct/protocols/layer4/udp.py
@@ -0,0 +1,26 @@
+"""
+User Datagram Protocol (TCP/IP protocol stack)
+"""
+from construct import *
+import six
+from binascii import unhexlify
+
+
+udp_header = Struct("udp_header",
+ Value("header_length", lambda ctx: 8),
+ UBInt16("source"),
+ UBInt16("destination"),
+ ExprAdapter(UBInt16("payload_length"),
+ encoder = lambda obj, ctx: obj + 8,
+ decoder = lambda obj, ctx: obj - 8,
+ ),
+ UBInt16("checksum"),
+)
+
+if __name__ == "__main__":
+ cap = unhexlify(six.b("0bcc003500280689"))
+ obj = udp_header.parse(cap)
+ print (obj)
+ print (repr(udp_header.build(obj)))
+
+