Tejas Arun Kokje <(E-Mail Removed)> writes:
> I want to write a unix socket program for two different machine
> architectures(Sparc & x86). I know that Internet protocols follow big
> endian architecture. Hence when do a send() from x86 architecture will
> send() implicilty convert buffer into big endian or I have to do htonl()
> explicitly before doing a send ?
send does not convert anything. How could it? It doesn't know what
kind of data you're sending!
Always use htonl and ntohl explicitely on _binary_ _data_.
Of course, you could rather use an ASCII protocol:
- since you have to convert with htonl or ntohl, converting to and
from ascii (printf and scanf) won't seem harder.
- you will be able to connect and try your server and client code
with telnet.
- you will be able to see what's going "on the wire" with tcpdump
or other tools with no need of decrypting hex dumps.
- you could end with less data to be transmited! For example,
geographic data (which consists mainly of numbers) is quite
smaller when expressed in ASCII than when put in binary.
--
__Pascal Bourguignon__
http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.