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

Hello Monks,

I need to know, how can I read socket syn data, sent from the client?
I'm using some gps tracking devices which connects to my tcp server written in Perl with IO::Socket::INET.
I'm perfectly receiving data from clients, but not the sync packet, which contains gps device id.
When the client device connects to the server firstly sends a sync packet and then continues with sending gps data.
As of manufacturer, sync packet format is:
typedef struct
{
WORD SyncHeader;

WORD SyncID;
DWORD UnitID;
} SyncStruct;

How can I get this data on socket connection?

Thanks in advance for your help.

Igor

Replies are listed 'Best First'.
Re: Socket syn data
by Corion (Patriarch) on Dec 08, 2008 at 19:05 UTC

    This seems to be a data structure described in the C language. Most likely, you will want to build a string using pack (or rather unpack) to decode the information from the GPS device. From reading the description, the following pack template might be what you want:

    my $template = 'vvV'; read $client, my $sync_packet, 8 or die "Couldn't read from client: $!"; my ($syncHeader, $syncID, $unitID) = unpack $template, $sync_packet; ...
Re: Socket syn data
by Wiggins (Hermit) on Dec 08, 2008 at 20:55 UTC
    Before going to a lot of programming effort; I suggest that you use a packet monitor on the wire to confirm that the data is really in the initial SYN packet. Even Net::RawIP would give you back the packets data.

    But one is puzzled why you aren't receiving at least 12(4+8) apparently garbage bytes at the beginning of the first read.

    Upon re-reading your message, I don't think the "socket syn data" (line 1) and the "manufacturer, sync packet format" are referring to the same thing . What is the manufactures definition of a "word" and "dword". Try starting with a 12 byte sysread() upon initial accept and then unpack that after determining the byte order (little or big endian).

    It is always better to have seen your target for yourself, rather than depend upon someone elses description.

      Hello

      Thanks to both of you for help.
      Solution from Corion worked perfectly!

      Thanks again!

      Igor V.