Re: getsockopt

Discussion in 'Python' started by Steve Holden, Dec 16, 2005.

  1. Steve Holden

    Steve Holden Guest

    Fabian Deutsch wrote:
    >>--- Urspr√ľngliche Nachricht ---
    >>Von: Steve Holden <>
    >>An:
    >>Betreff: Re: getsockopt
    >>Datum: Fri, 16 Dec 2005 08:29:08 +0000
    >>
    >>Fabian Deutsch wrote:
    >>
    >>>Hello,
    >>>
    >>>my name is fabian and i'm a student from northern germany. right now i
    >>>try to create som kind of decapsulation of esp-udp packets using python.
    >>>
    >>>therefor i need to use the socket.getsockopt (SOL_IP, IP_OPTIONS, 20)
    >>>method. But al i get is some empty value. Nothin.
    >>>
    >>>Does someone know or have an working exmaple of how to use this method??
    >>>
    >>>The lines:
    >>>s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)
    >>>s.bind(('',4500))
    >>>while 1: # Run until cancelled
    >>> message, client = s.recvfrom(1400) # <=256 byte datagram
    >>> hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20)
    >>> print "Client connected:", client
    >>> print "HDR:" + binascii.hexlify(hdr)
    >>>

    >>
    >>Perhaps you're getting an empty string back because no IP options are
    >>set in the received packets' headers?
    >>

    >
    > Hey,
    > you are right - i just re-read the ip (7) man - i only get the ip options ..
    >
    > but do you know a way of getting the whole header?
    >
    > 'cause what i'm trying to do is, to "remove" the udp-header of the packet i
    > recieved and sendind a new packet without the udp-header.
    > I want to do this by taking it's payload (incl. esp-hdr) and ip-header and
    > resending it to my system creating a new packet with the old ip-header and
    > payload (incl. esp-hdr) i got from the recvd packet.
    >
    > Before:
    > +--------+---------+----------+----------- - -
    > | IP HDR | UDP HDR | ESP HDR | PAYLOAD ...
    > +--------+---------+----------+----------- - -
    > After :
    > +--------+---------+----------- - -
    > | IP HDR | ESP HDR | PAYLOAD ...
    > +--------+---------+----------- - -
    >

    I'm not sure where ESP is going to come into this, or how the traffic
    you will be receiving will be generated. I suspect you may need to
    reconsider your application design a little.

    The only way to get hold of the IP headers is to use SOCK_RAW, which
    delivers everything that comes in from the packet driver.

    What is it you're actually trying to do? If you perform the
    transformation you outline in the diagrams above then the IP header will
    certainly contain the wrong protocol value for a start.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
     
    Steve Holden, Dec 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabian Deutsch

    getsockopt

    Fabian Deutsch, Dec 16, 2005, in forum: Python
    Replies:
    0
    Views:
    536
    Fabian Deutsch
    Dec 16, 2005
  2. Ashwin Rao
    Replies:
    2
    Views:
    1,063
    Martien Verbruggen
    Dec 3, 2009
  3. chris
    Replies:
    0
    Views:
    862
    chris
    May 21, 2010
  4. chris
    Replies:
    0
    Views:
    1,224
    chris
    May 21, 2010
Loading...

Share This Page