Skip site navigation (1) Skip section navigation (2)

Network Byte Order Coercion

From: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
To: PostgreSQL Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Network Byte Order Coercion
Date: 2005-05-16 10:12:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces

In libpq example program 3 (testlibpq3.c), an int4 field is converted
to host byte order:

/* Get the field values (we ignore possibility they are null!) */
iptr = PQgetvalue(res, i, i_fnum);

 * The binary representation of INT4 is in network byte order,
 * which we'd better coerce to the local byte order.
ival = ntohl(*((uint32_t *) iptr));

(As I saw while reading "An Essay on Endian Order" [1]) I'm not so
familiar with byte orders, but what's the point of coercion in here?
Should we do it in every integer field we retrieved? What's the
[dis]advantages of this? I'd be so appreciated for any explanation.




pgsql-interfaces by date

Next:From: Christoph HallerDate: 2005-05-18 11:09:42
Subject: Re: Network Byte Order Coercion
Previous:From: Tom LaneDate: 2005-05-14 18:51:13
Subject: Re: Two seperate problems with libpq - arrays and bytea edit

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group