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 09:26:53 -0800


Kevin <root AT zazu.nol.org> writes:
^^^^^^^^^^^^^^^^^ Kevin, mail to this address bounces.

> Tom May wrote:
> > Assuming that a short is two chars is not a portable way to do things.
> > If I were sure of exactly what you're trying to do, I would suggest a
> > better way, but I'm not, so I won't.
>
> Basically, all I'm trying to do is get around the endian problem
> with the MSSQL server...it sends short values as 2 bytes, switching hi
> and low bytes depending on your systems endianess. The tds_get_smallint
> function was backfiring on me on Solaris, as the function was assuming
> little-endian form, while the server was sending the value as
> big-endian.
> The code there was done to eliminate the use of pound defines, as per
> instructions from my boss. :)
> I've only been getting paid to program for a bit over a year now,

Cool. Getting involved with free software is a good way to learn a
lot.

> so I'm not as up to par on portability as I'd like...what would you
> suggest? Feel free to ignore this and flame me if this is an
> inapproriate
> question for this list :)

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?


TDS_SMALLINT tds_get_smallint(TDSSOCKET *tds) {
char buff[2];
u_short ms_kludge;

buff[0] = tds_get_byte(tds);
buff[1] = tds_get_byte(tds);
ms_kludge = *((short*)buff);
return ((TDS_SMALLINT)ms_kludge);
}

On a little endian machine this is equivalent to:

TDS_SMALLINT tds_get_smallint(TDSSOCKET *tds) {
int a, b;

a = tds_get_byte(tds);
b = tds_get_byte(tds);
return (b << 8) | a;
}

On a big endian machine it is equivalent to:

TDS_SMALLINT tds_get_smallint(TDSSOCKET *tds) {
int a, b;

a = tds_get_byte(tds);
b = tds_get_byte(tds);
return (a << 8) | b;
}

Assuming tds_get_byte() returns bytes in the order they come in on the
wire (and that it returns stuff in the range 0-255 and not -127 to
128) , this looks wrong because tds_get_smallint() would return a
different value depending on the endianness of the machine it's
running on.

So, what is the byte order on the wire? And does it depend on
information the two machines know about each other's endianness?

Tom.




Archive powered by MHonArc 2.6.24.

Top of Page