Startup messages for socket protocol - Mailing list pgsql-general

From Guillaume Yziquel
Subject Startup messages for socket protocol
Date
Msg-id 20110317142041.GX22969@localhost
Whole thread Raw
Responses Re: Startup messages for socket protocol
List pgsql-general
Hi.

I've been trying to get a connection working to a PostgreSQL server
through the socket-level protocol. I've therefore been looking at
fe-connect.c and fe-protocol3.c in the src/interfaces/libpq folder.

Reading those sources, I understood, that the startup message should
begin with a request from the client with the protocol number.

In fe-protocol3.c, build_startup_message():

        /* Protocol version comes first. */
        if (packet)
        {
                ProtocolVersion pv = htonl(conn->pversion);

                memcpy(packet + packet_len, &pv, sizeof(ProtocolVersion));
        }
        packet_len += sizeof(ProtocolVersion);

However, when I try to send this as the first thing, I get disconnected
by the server. Reading what the psql program does, I first get an 8 byte
message containing this:

            \000\000\000\008\004\210\022/

This seems to work, but I'm at a loss pinpointing in the libpq source
code where that would fit in the protocol.

Enlightenment would be very welcome.

--
     Guillaume Yziquel

pgsql-general by date:

Previous
From: Alexander Farber
Date:
Subject: Re: A join of 2 tables with sum(column) > 30
Next
From: "Gauthier, Dave"
Date:
Subject: Getting users/privs for tables.