[Win2k - Version 8.0.2] - StartupMessage Format Question

From: "Tom Pfeifer" <tpfeifer(at)tela(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: [Win2k - Version 8.0.2] - StartupMessage Format Question
Date: 2005-05-15 00:04:14
Message-ID: 20050514234559.M34887@tela.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I don't know where to go with this question.
If this is the wrong place, please disregard.

I'm trying to learn more about how to connect to the backend with perl, not using DBI, just
straight perl (pure perl).  I feel like an idiot asking this question, but I don't seem to
understand what the "zero byte" terminator is.  What is the equivalent ASCII character?  Or is perl
unable to process this "zero byte" terminator?

This is the page I am lookin at in the docs:
http://www.postgresql.org/docs/8.0/static/protocol-message-formats.html

This is the location I am reviewing in the docs:
StartupMessage (F)

This is the attempted connection:
00 00 00 22 00 03 00 00 75 73 65 72 20 70 6F 73  ..."....user pos
74 67 72 65 73 20 64 61 74 61 62 61 73 65 20 6D  tgres database m
61 61 63 68 00 00                                aach..

This is the result:
45 00 00 00 7E 53 46 41 54 41 4C 00 43 30 38 50 E...~SFATAL.C08P
30 31 00 4D 69 6E 76 61 6C 69 64 20 73 74 61 72 01.Minvalid star
74 75 70 20 70 61 63 6B 65 74 20 6C 61 79 6F 75 tup packet layou
74 3A 20 65 78 70 65 63 74 65 64 20 74 65 72 6D t: expected term
69 6E 61 74 6F 72 20 61 73 20 6C 61 73 74 20 62 inator as last b
79 74 65 00 46 70 6F 73 74 6D 61 73 74 65 72 2E yte.Fpostmaster.
63 00 4C 31 34 39 31 00 52 50 72 6F 63 65 73 73 c.L1491.RProcess
53 74 61 72 74 75 70 50 61 63 6B 65 74 00 00 StartupPacket..

This is the code:
use IO::Socket;
$string = 'user postgres database maach';
$version = pack('Nnna30', 34, 3, 0, $string);
print "\n";
while ($version =~ m/(.{1,16})/g) {
my $chunk = $1;
print join ' ', map {sprintf '%02X', ord $_} split //, $chunk;
print ' ' x (16 - length $chunk);
print ' ';
print join '', map { sprintf '%s', (/[[:graph:] ]/) ? $_ : '.' } split //, $chunk;
print "\n";
}
$remote = IO::Socket::INET->new(PeerAddr => '127.0.0.1',
PeerPort => '5432',
Proto => 'tcp', Timeout => '30') or die "error:$!";
$remote->autoflush(1);
print $remote $version;
while ( <$remote> ) {
print "\n";
while ($_ =~ m/(.{1,16})/g) {
my $chunk = $1;
print join ' ', map {sprintf '%02X', ord $_} split //, $chunk;
print ' ' x (16 - length $chunk);
print ' ';
print join '', map { sprintf '%s', (/[[:graph:] ]/) ? $_ : '.' } split //, $chunk;
print "\n";
}
}
$remote->close;
exit(0);

Thanks,
T Pfeifer

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Olivier Thauvin 2005-05-15 01:04:16 Re: [Win2k - Version 8.0.2] - StartupMessage Format Question
Previous Message Jeff Eckermann 2005-05-14 15:24:19 Re: Can null values be sorted low?