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
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
e2c89ae0
Commit
e2c89ae0
authored
8 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup IPv6 addresses with "::" handling
parent
61191024
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/pton_ntop.py
+7
-15
7 additions, 15 deletions
scapy/pton_ntop.py
with
7 additions
and
15 deletions
scapy/pton_ntop.py
+
7
−
15
View file @
e2c89ae0
...
...
@@ -25,24 +25,18 @@ def inet_pton(af, addr):
return
socket
.
inet_pton
(
af
,
addr
)
except
AttributeError
:
pass
# IPv6: The use of "::" indicates one or more groups of 16 bits of zeros.
# We deal with this form of wildcard using a special marker.
JOKER
=
"
*
"
while
"
::
"
in
addr
:
addr
=
addr
.
replace
(
"
::
"
,
"
:
"
+
JOKER
+
"
:
"
)
joker_pos
=
None
joker_pos
=
None
result
=
""
parts
=
addr
.
split
(
"
:
"
)
nparts
=
len
(
parts
)
for
i
,
part
in
enumerate
(
parts
):
if
part
==
JOKER
:
#
Wildcard is only allowed once
if
not
part
:
#
"::" indicates one or more groups of 2 null bytes
if
joker_pos
is
None
:
joker_pos
=
len
(
result
)
joker_pos
=
len
(
result
)
else
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
# Wildcard is only allowed once
raise
Exception
(
"
Illegal syntax for IP address
"
)
elif
i
+
1
==
nparts
and
'
.
'
in
part
:
# The last part of an IPv6 address can be an IPv4 address
try
:
...
...
@@ -55,12 +49,10 @@ def inet_pton(af, addr):
result
+=
part
.
rjust
(
4
,
"
0
"
).
decode
(
"
hex
"
)
except
TypeError
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
# If there's a wildcard, fill up with zeros to reach 128bit (16 bytes)
if
JOKER
in
addr
:
if
joker_pos
is
not
None
:
result
=
(
result
[:
joker_pos
]
+
"
\x00
"
*
(
16
-
len
(
result
))
+
result
[
joker_pos
:])
if
len
(
result
)
!=
16
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
return
result
...
...
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
register
or
sign in
to comment