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
47fca065
Commit
47fca065
authored
8 years ago
by
Guillaume Valadon
Browse files
Options
Downloads
Patches
Plain Diff
Use socket.pton & socket.ntop is available
parent
c751e92f
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
+17
-11
17 additions, 11 deletions
scapy/pton_ntop.py
with
17 additions
and
11 deletions
scapy/pton_ntop.py
+
17
−
11
View file @
47fca065
...
...
@@ -17,6 +17,12 @@ def inet_pton(af, addr):
if
af
==
socket
.
AF_INET
:
return
socket
.
inet_aton
(
addr
)
elif
af
==
socket
.
AF_INET6
:
# Use inet_pton if available
try
:
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
=
"
*
"
...
...
@@ -65,6 +71,12 @@ def inet_ntop(af, addr):
if
af
==
socket
.
AF_INET
:
return
socket
.
inet_ntoa
(
addr
)
elif
af
==
socket
.
AF_INET6
:
# Use inet_ntop if available
try
:
return
socket
.
inet_ntop
(
af
,
addr
)
except
AttributeError
:
pass
# IPv6 addresses have 128bits (16 bytes)
if
len
(
addr
)
!=
16
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
...
...
@@ -75,15 +87,9 @@ def inet_ntop(af, addr):
hexstr
=
hex
(
value
)[
2
:]
except
TypeError
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
parts
.
append
(
hexstr
.
lstrip
(
"
0
"
).
lower
())
result
=
"
:
"
.
join
(
parts
)
while
"
:::
"
in
result
:
result
=
result
.
replace
(
"
:::
"
,
"
::
"
)
# Leaving out leading and trailing zeros is only allowed with ::
if
result
.
endswith
(
"
:
"
)
and
not
result
.
endswith
(
"
::
"
):
result
=
result
+
"
0
"
if
result
.
startswith
(
"
:
"
)
and
not
result
.
startswith
(
"
::
"
):
result
=
"
0
"
+
result
return
result
parts
.
append
(
hexstr
.
lower
())
# Note: the returned address is never compact
return
"
:
"
.
join
(
parts
)
else
:
raise
Exception
(
"
Address family not supported yet
"
)
raise
Exception
(
"
Address family not supported yet
"
)
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