我在斯卡比实施GTPv2。目前的定义如下:
class _GTPv2IE_HDR(Packet):
fields_desc = [ ByteEnumField("type", None, gtpv2_ie_types),
ShortField("length", None),
BitField("spare", 0, 4),
BitField("instance", 0, 4) ]
class GTPv2IE(Packet):
name = "GTPv2 Information Element"
fields_desc = [ _GTPv2IE_HDR ]
def extract_padding(self, p):
return "", p
def post_build(self, p, pay):
if self.length is None:
l = len(p) - 4
p = p[:1] + struct.pack("!H", l) + p[3:]
return p + pay
GTPv2IE是信息元素的基类(类似于ipv6中的ext报头)。在
我是如何定义IE的:
^{pr2}$现在GTPv2包本身在fields_desc列表的末尾有以下字段:
PacketListField("info_elements", [], GTPv2IE, length_from=lambda p:p.length-4-(4 if p.flags & 0x8 != 0 else 0)))
问题是当我创建GTPv2包时:
pkt = IP(dst='2.2.2.2') / UDP() / GTPv2(info_elements=[GTPv2IE_Recovery()])
然后调用show2()得到:
###[ IP ]###
version= 4L
ihl= 5L
tos= 0x0
len= 41
id= 1
flags=
frag= 0L
ttl= 64
proto= udp
chksum= 0x7465
src= 1.1.1.90
dst= 2.2.2.2
\options\
###[ UDP ]###
sport= 2123
dport= 2123
len= 21
chksum= 0xc380
###[ GTPv2 ]###
version= 2L
flags=
type= echo_request
length= 9
sequence= 0x3a444d
spare2= 0
\info_elements\
|###[ GTPv2 Information Element ]###
| type= recovery
| length= 1
| spare= 0L
| instance= 0L
|###[ GTPv2 Information Element ]###
| type= 90
| length= None
| spare= 0
| instance= 0
show()方法按预期工作:
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64
proto= udp
chksum= None
src= 1.1.1.90
dst= 2.2.2.2
\options\
###[ UDP ]###
sport= 2123
dport= 2123
len= None
chksum= None
###[ GTPv2 ]###
version= 2
flags=
type= echo_request
length= None
sequence= None
spare2= 0
\info_elements\
|###[ GTPv2 Recovery IE ]###
| type= recovery
| length= None
| spare= 0
| instance= 0
| recovery= None
谢谢你们的帮助。在
亚历克斯。在
我得到了这个结果(以IPOption为例):
我在GTPv2IE基类中添加了2个classmethods,如下所示:
现在show2()按预期工作:
^{pr2}$相关问题 更多 >
编程相关推荐