More on using FreeTDS on a server (was Re: [freetds] Server dumpscore...)

Steve Kirkendall skirkendall at
Thu Apr 22 23:50:25 EDT 2004

"James K. Lowden" <jklowden at> wrote on Thursday, Apr 22, 2004:
> On Tue, 20 Apr 2004, Steve Kirkendall <skirkendall at> wrote:
> > There's no way for high-level functions to know what type of packet is
> >   received, because the tds_read_packet() function discards that byte.
> >   I added an in_flag field to the TDSSOCKET structure, 
> Perhaps "in_flag" would be better named "token" or "packet_type"?

I chose the name "in_flag" because TDSSOCKET already contains a field
named "out_flag" which seems to control the packet type for any outgoing
packets.  There are a lot of "in_XXX" and "out_XXX" field names, so I
was trying to continue that symmetry.

But now I wonder if it really matters.  The received packet type seems
to be superfluous.  I originally wanted to know the packet type partly so
my server could automatically distinguish between TDS7.0 and TDS4.2/5.0
logins (in 0x10 and 0x02 packets, respectively), and partly so it could
treat the entire content of a 0x01 query packet as the text of a query,
while still allowing RPC calls in 0x04 packets.

But Mike C. points out that 7.0 uses a prelogin packet, so my server
should be able to detect the login type that way.

I thought the entire content of a 0x01 packet was a query because the
tsql program seems to send them that way.  The tds_get_query() function
expects a 6-byte header at the start of each query, so it doesn't work
correctly with tsql.  But it looks like the tds_get_query() function is
right, and tsql is wrong.  Maybe.  I'm not 100% confident of that; I'll
look into it tomorrow.

If both of those things are right (prelogin to detect 7.0 logins, and
token header for queries) then the server doesn't need to know the
received packet type anymore than the client does.  My "in_flag"
modification wouldn't be necessary.

Steve Kirkendall    |A:It is confusing, since people don't read that way
kirkenda at |Q:Why is top-posting bad?
                    |A:It is adding comments to the top of a message
                    |Q:What is top-posting?

More information about the FreeTDS mailing list