Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:58:48+00:00 2026-06-15T08:58:48+00:00

I’m implementing GTPv2 in scapy. The current definition is as follows: class _GTPv2IE_HDR(Packet): fields_desc

  • 0

I’m implementing GTPv2 in scapy. The current definition is as follows:

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

As you can GTPv2IE is the base class for information elements (similar to ext headers in ipv6).

Here’s how I define an IE:

class GTPv2IE_Recovery(GTPv2IE):
    name = "GTPv2 Recovery IE"
    type = 3
    fields_desc = [ _GTPv2IE_HDR,
                    ByteField("recovery", None) ]
    def post_build(self, p, pay):
        if self.recovery is None:
            rec = random.getrandbits(8)
            p = p[:4] + struct.pack("B", rec)
        return GTPv2IE.post_build(self, p, pay)

Now the GTPv2 packet itself has the following field at the end of fields_desc list:

PacketListField("info_elements", [], GTPv2IE, length_from=lambda p:p.length-4-(4 if p.flags & 0x8 != 0 else 0)))

The issue is when I create a GTPv2 packet:

pkt = IP(dst='2.2.2.2') / UDP() / GTPv2(info_elements=[GTPv2IE_Recovery()])

And call show2() I get:

###[ 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

The show() method works as expected:

###[ 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

Thanks for your help guys.

Alex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:58:49+00:00Added an answer on June 15, 2026 at 8:58 am

    I’ve got this working (took IPOption as an example):

    I added 2 classmethods to GTPv2IE base class as follows:

    registered_info_elements = {}
    @classmethod
    def register_variant(cls):
        cls.registered_info_elements[cls.type.default] = cls
    @classmethod
    def dispatch_hook(cls, pkt=None, *args, **kargs):
        if pkt:
            t = ord(pkt[0])
            return cls.registered_info_elements.get(t, cls)
        return cls
    

    Now show2() works as expected:

    >>> pkt.show2()
    ###[ IP ]###
      version= 4L
      ihl= 5L
      tos= 0x0
      len= 46
      id= 1
      flags= 
      frag= 0L
      ttl= 64
      proto= udp
      chksum= 0x7607
      src= 1.1.1.90
      dst= 1.1.1.92
      \options\
    ###[ UDP ]###
         sport= 2123
         dport= 2123
         len= 26
         chksum= 0x52da
    ###[ GTPv2 ]###
            version= 2L
            flags= 
            type= echo_request
            length= 14
            sequence= 0x8ce2a1
            spare2= 0
            \info_elements\
             |###[ GTPv2 Recovery IE ]###
             |  type= recovery
             |  length= 1
             |  spare= 0L
             |  instance= 0L
             |  recovery= 37
             |###[ GTPv2 Sending Node Features IE ]###
             |  type= node_features
             |  length= 1
             |  spare= 0L
             |  instance= 0L
             |  node_features= PRN+MABR+NTSR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.