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
dd093b18
Commit
dd093b18
authored
16 years ago
by
Phil
Browse files
Options
Downloads
Patches
Plain Diff
Added MultiEnumField for fields whose text also depends on another field
ex: ICMP code field
parent
3ad52667
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/fields.py
+30
-0
30 additions, 0 deletions
scapy/fields.py
with
30 additions
and
0 deletions
scapy/fields.py
+
30
−
0
View file @
dd093b18
...
...
@@ -769,6 +769,36 @@ class XShortEnumField(ShortEnumField):
return
self
.
i2s
[
x
]
return
lhex
(
x
)
class
MultiEnumField
(
EnumField
):
def
__init__
(
self
,
name
,
default
,
enum
,
depends_on
,
fmt
=
"
H
"
):
self
.
depends_on
=
depends_on
self
.
i2s_multi
=
enum
self
.
s2i_multi
=
{}
self
.
s2i_all
=
{}
for
m
in
enum
:
self
.
s2i_multi
[
m
]
=
s2i
=
{}
for
k
,
v
in
enum
[
m
].
iteritems
():
s2i
[
v
]
=
k
self
.
s2i_all
[
v
]
=
k
Field
.
__init__
(
self
,
name
,
default
,
fmt
)
def
any2i_one
(
self
,
pkt
,
x
):
if
type
(
x
)
is
str
:
v
=
self
.
depends_on
(
pkt
)
if
v
in
self
.
s2i_multi
:
s2i
=
self
.
s2i_multi
[
v
]
if
x
in
s2i
:
return
s2i
[
x
]
return
self
.
s2i_all
[
x
]
return
x
def
i2repr_one
(
self
,
pkt
,
x
):
v
=
self
.
depends_on
(
pkt
)
if
v
in
self
.
i2s_multi
:
return
self
.
i2s_multi
[
v
].
get
(
x
,
x
)
return
x
# Little endian long field
class
LELongField
(
Field
):
def
__init__
(
self
,
name
,
default
):
...
...
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