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
4d8b461e
Commit
4d8b461e
authored
8 years ago
by
Guillaume Valadon
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #545 from p-l-/enh-flags
Flags: allow operations (| & ==) with strings
parents
f982008e
a6b12fc6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/fields.py
+10
-17
10 additions, 17 deletions
scapy/fields.py
test/regression.uts
+12
-0
12 additions, 0 deletions
test/regression.uts
with
22 additions
and
17 deletions
scapy/fields.py
+
10
−
17
View file @
4d8b461e
...
@@ -1015,40 +1015,33 @@ class LEFieldLenField(FieldLenField):
...
@@ -1015,40 +1015,33 @@ class LEFieldLenField(FieldLenField):
class
FlagValue
(
object
):
class
FlagValue
(
object
):
__slots__
=
[
"
value
"
,
"
names
"
,
"
multi
"
]
__slots__
=
[
"
value
"
,
"
names
"
,
"
multi
"
]
@staticmethod
def
_fixvalue
(
self
,
value
):
def
__fixvalue
(
value
,
names
):
if
isinstance
(
value
,
basestring
):
if
isinstance
(
value
,
basestring
):
if
isinstance
(
names
,
list
):
value
=
value
.
split
(
'
+
'
)
if
self
.
multi
else
list
(
value
)
value
=
value
.
split
(
'
+
'
)
else
:
value
=
list
(
value
)
if
isinstance
(
value
,
list
):
if
isinstance
(
value
,
list
):
y
=
0
y
=
0
for
i
in
value
:
for
i
in
value
:
y
|=
1
<<
names
.
index
(
i
)
y
|=
1
<<
self
.
names
.
index
(
i
)
value
=
y
value
=
y
return
value
return
None
if
value
is
None
else
int
(
value
)
def
__init__
(
self
,
value
,
names
):
def
__init__
(
self
,
value
,
names
):
self
.
value
=
(
value
.
value
if
isinstance
(
value
,
self
.
__class__
)
else
self
.
__fixvalue
(
value
,
names
))
self
.
multi
=
isinstance
(
names
,
list
)
self
.
multi
=
isinstance
(
names
,
list
)
self
.
names
=
names
self
.
names
=
names
self
.
value
=
self
.
_fixvalue
(
value
)
def
__int__
(
self
):
def
__int__
(
self
):
return
self
.
value
return
self
.
value
def
__cmp__
(
self
,
other
):
def
__cmp__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
return
cmp
(
self
.
value
,
self
.
_fixvalue
(
other
))
return
cmp
(
self
.
value
,
other
.
value
)
return
cmp
(
self
.
value
,
other
)
def
__and__
(
self
,
other
):
def
__and__
(
self
,
other
):
return
self
.
__class__
(
self
.
value
&
int
(
other
),
self
.
names
)
return
self
.
__class__
(
self
.
value
&
self
.
_fixvalue
(
other
),
self
.
names
)
__rand__
=
__and__
__rand__
=
__and__
def
__or__
(
self
,
other
):
def
__or__
(
self
,
other
):
return
self
.
__class__
(
self
.
value
|
int
(
other
),
self
.
names
)
return
self
.
__class__
(
self
.
value
|
self
.
_fixvalue
(
other
),
self
.
names
)
__ror__
=
__or__
__ror__
=
__or__
def
__lshift__
(
self
,
other
):
def
__lshift__
(
self
,
other
):
return
self
.
value
<<
int
(
other
)
return
self
.
value
<<
self
.
_fixvalue
(
other
)
def
__rshift__
(
self
,
other
):
def
__rshift__
(
self
,
other
):
return
self
.
value
>>
int
(
other
)
return
self
.
value
>>
self
.
_fixvalue
(
other
)
def
__nonzero__
(
self
):
def
__nonzero__
(
self
):
return
bool
(
self
.
value
)
return
bool
(
self
.
value
)
def
flagrepr
(
self
):
def
flagrepr
(
self
):
...
...
This diff is collapsed.
Click to expand it.
test/regression.uts
+
12
−
0
View file @
4d8b461e
...
@@ -7211,6 +7211,12 @@ assert not pkt.flags.MF
...
@@ -7211,6 +7211,12 @@ assert not pkt.flags.MF
assert pkt.flags.DF
assert pkt.flags.DF
assert not pkt.flags.evil
assert not pkt.flags.evil
assert repr(pkt.flags) == '<Flag 2 (DF)>'
assert repr(pkt.flags) == '<Flag 2 (DF)>'
pkt.flags |= 'evil+MF'
pkt.flags &= 'DF+MF'
assert pkt.flags.MF
assert pkt.flags.DF
assert not pkt.flags.evil
assert repr(pkt.flags) == '<Flag 3 (MF+DF)>'
pkt = IP(flags=3)
pkt = IP(flags=3)
assert pkt.flags.MF
assert pkt.flags.MF
...
@@ -7240,6 +7246,12 @@ assert pkt.flags.U
...
@@ -7240,6 +7246,12 @@ assert pkt.flags.U
assert pkt.flags.AU
assert pkt.flags.AU
assert not any(getattr(pkt.flags, f) for f in 'FSRPECN')
assert not any(getattr(pkt.flags, f) for f in 'FSRPECN')
assert repr(pkt.flags) == '<Flag 48 (AU)>'
assert repr(pkt.flags) == '<Flag 48 (AU)>'
pkt.flags &= 'SFA'
pkt.flags |= 'P'
assert pkt.flags.P
assert pkt.flags.A
assert pkt.flags.PA
assert not any(getattr(pkt.flags, f) for f in 'FSRUECN')
pkt = TCP(flags=56)
pkt = TCP(flags=56)
assert all(getattr(pkt.flags, f) for f in 'PAU')
assert all(getattr(pkt.flags, f) for f in 'PAU')
...
...
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