Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
10210cbe
Commit
10210cbe
authored
Jun 27, 2017
by
Guillaume Valadon
Browse files
Options
Downloads
Patches
Plain Diff
checksum() example added in doc
parent
58a985f1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/scapy/functions.rst
+40
-0
40 additions, 0 deletions
doc/scapy/functions.rst
doc/scapy/index.rst
+1
-0
1 addition, 0 deletions
doc/scapy/index.rst
with
41 additions
and
0 deletions
doc/scapy/functions.rst
0 → 100644
+
40
−
0
View file @
10210cbe
***********************
Calling Scapy functions
***********************
This section provides some examples that show how to benefit from Scapy
functions in your own code.
UDP checksum
============
The following example explains howto use the checksum() function to compute and
UDP checksum manually. The following steps must be performed:
1. compute the UDP pseudo header as described in RFC768
2. build an UDP packet with Scapy with p[UDP].chksum=0
3. call checksum() with the pseudo header and the UDP packet
::
from scapy.all import *
def pseudo_header(ip_src, ip_dst, ip_proto, length):
"""
Return a pseudo header according to RFC768
"""
# Prepare the binary representation of the pseudo header
return struct.pack("!4s4sHH", inet_aton(ip_src), inet_aton(ip_dst), ip_proto, length)
# Get the UDP checksum computed by Scapy
packet = IP(dst="10.11.12.13", src="10.11.12.14")/UDP()/DNS()
packet_raw = str(packet)
checksum_scapy = IP(packet_raw)[UDP].chksum
# Set the UDP checksum to 0 and compute the checksum 'manually'
packet = IP(dst="10.11.12.13", src="10.11.12.14")/UDP(chksum=0)/DNS()
packet_raw = str(packet)
udp_raw = packet_raw[20:]
phdr = pseudo_header(packet.src, packet.dst, socket.IPPROTO_UDP, len(udp_raw))
assert(checksum_scapy == checksum(phdr + udp_raw))
This diff is collapsed.
Click to expand it.
doc/scapy/index.rst
+
1
−
0
View file @
10210cbe
...
@@ -21,6 +21,7 @@ This document is under a `Creative Commons Attribution - Non-Commercial
...
@@ -21,6 +21,7 @@ This document is under a `Creative Commons Attribution - Non-Commercial
advanced_usage
advanced_usage
extending
extending
build_dissect
build_dissect
functions
troubleshooting
troubleshooting
development
development
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment