Skip to Content.
Sympa Menu

freetds - Re: Getting FreeTDS up under Solaris

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Tom May <tom AT go2net.com>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: Re: Getting FreeTDS up under Solaris
  • Date: 21 Dec 1998 10:30:26 -0800


Kevin <root AT zazu.nol.org> writes:

> > I just need a little more context for what you're trying to do because
> > I haven't actually downloaded any freetds source (I'm just keeping an
> > eye on the list). Here are the two versions you've posted:
> >
> > # if defined(HW_LITTLE_ENDIAN)
> > lobyte = tds_get_byte(tds);
> > hibyte = tds_get_byte(tds);
> > #elif defined(HW_BIG_ENDIAN)
> > hibyte = tds_get_byte(tds);
> > lobyte = tds_get_byte(tds);
> > #else
> > #error Endianess not defined!
> > #endif
> >
> > Then what happens to lobyte and hibyte?
> return (TDS_SMALLINT)lobyte+(hibyte*256)
>
> > So, what is the byte order on the wire? And does it depend on
> > information the two machines know about each other's endianness?
> Byte order is translated by the MSSQL server to the client's byte
> order
> as near as I've been able to tell...

That's certainly consistent with your code. Although it hardly makes
sense to have the server do work for hundreds of clients that the
clients could be doing for themselves.

Anyway, if I were writing the code I'd do it the #define way because
1) it's more efficient than rebuffering through memory, 2) it avoids
assumptions about the size of short, 3) it's easier to understand and
is more obviously correct given that you know the server has tweaked
the byte order for the client's endianness.

Alternatively depending on how tds_get_byte() works maybe you can just
pull it out of a buffer with something like
*(TDS_SMALLINT*)buffer_read_ptr although that may break on some
architectures depending on data alignment and there may be problems
with a value spanning multiple buffers.

The non-#define solution might be happy if you just use TDS_SMALLINT
instead of short because at some point there are probably other
assumptions in the code that sizeof(TDS_SMALLINT) == 2 which seems
reasonable because TDS_SMALLINT should be hand picked per architecture
as the 2-byte data type. (Actually my code fragment in the previous
paragraph assumes this.)

Tom.




Archive powered by MHonArc 2.6.24.

Top of Page