Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks,

I have an application that connects to a remote machine using IO::Socket. My problem is that the guys on the remote machine are telling me that I need to send certain data in the "TCP Header", which is something that is distinct from the data that I send using "print $socket" (where $socket is the IO:Socket object).

What is the TCP Header and how do I manipulate what goes in into it?

Thanks in advance.

Gorby

Replies are listed 'Best First'.
Re: TCP Headers
by dws (Chancellor) on Mar 23, 2004 at 04:55 UTC

    My problem is that the guys on the remote machine are telling me that I need to send certain data in the "TCP Header", which is something that is distinct from the data that I send using "print $socket"

    This sounds kind of oddball, since application-level stuff doesn't see TCP headers unless it's doing something like sniffing traffic. Can you say something about what you're trying to do? What kind of server/service are you trying to talk to? And what, specifically, are the server guys telling you that you need to add?

      What the server guys are saying is that I have to send some data aside from the actual user data. For example, if the user data I want to send is:

      1234567890

      They want me to send the following non related data in the tcp header:

      6001710001

      How do I manipulate the TCP header? For that matter, what is a TCP header?

      Thanks.

      Gorby
        The part of the TCP header you can set is a series of flags and possibly some key-value pairs that give instructions or information to your system's TCP stack and the TCP stack of the system you're communicating with about any special handling that connection may need. The header also contains sequence numbers and some other stuff, but you generally don't set that.

        It doesn't really make sense to say "put 6001710001 in the TCP header" without saying where you want it put, and even if you did say where it still wouldn't make a ton of sense. It could make sense to say "Set the SYN flag in the TCP header" or "Set the TimeStamp TCP header to X", but that's still a strange thing to do.

        I suspect you're miscommunicating somehow with your server guys. Why don't you see if they can tell you more precisely what they want you to do.

Re: TCP Headers
by toma (Vicar) on Mar 23, 2004 at 05:00 UTC
    Net::RawIP looks interesting.

    It should work perfectly the first time! - toma
Re: TCP Headers
by neniro (Priest) on Mar 23, 2004 at 17:13 UTC
    Try hping2 for playing around with TCP/IP - you can manipulate almost everything.
Re: TCP Headers
by leriksen (Curate) on Mar 25, 2004 at 03:55 UTC
    Its possible they want something in the TCP header to help them dispatch the body to the right portion of their system, as they may have a custom TCP stack (why is a completely different question). You may be able to get the required effect by using a IOCTL call. RTFM for what can be changed in a socket via IOCTL, and get them to better define the required portion of the TCP header that needs adjustment.

    I know the IP packet has a protocol field to enable 'passing up' of the packet contents to the right layer (generally TCP, but it could be UDP, or a custom protocol), abd X.25 has an 'application specific' field so that registered X.25 apps can listen for packets.

    +++++++++++++++++
    #!/usr/bin/perl
    use warnings;use strict;use brain;