Networking Forums

Networking Forums > Computer Networking > Linux Networking > endianess question

Reply
Thread Tools Display Modes

endianess question

 
 
Tejas Arun Kokje
Guest
Posts: n/a

 
      09-09-2004, 10:34 PM

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 ?

Tejas Kokje
University of Southern California

 
Reply With Quote
 
 
 
 
Phil Frisbie, Jr.
Guest
Posts: n/a

 
      09-09-2004, 10:51 PM
Tejas Arun Kokje wrote:
> 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 ?


IP packets use big endian order. A socket just sends bytes and knows nothing
about what type of data is actually being sent.

It is up to you to decide whether to use big or little endian order in your
messages, and convert when needed. I would decide if most of your machines will
be big or little endian, and then choose the most used one so that most machines
will not need to convert the data.

> Tejas Kokje
> University of Southern California


--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

 
Reply With Quote
 
ray
Guest
Posts: n/a

 
      09-10-2004, 12:41 AM
On Thu, 09 Sep 2004 15:34:04 +0000, Tejas Arun Kokje wrote:

>
> 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 ?
>
> Tejas Kokje
> University of Southern California


If you always do hton__ and ntoh__, you will have no problems, and your
code will be portable.

 
Reply With Quote
 
Wolf
Guest
Posts: n/a

 
      09-10-2004, 12:43 AM
"Phil Frisbie, Jr." <(E-Mail Removed)> wrote in message
news:x750d.12919$(E-Mail Removed)...
> Tejas Arun Kokje wrote:
> > 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 ?

>
> IP packets use big endian order. A socket just sends bytes and knows

nothing
> about what type of data is actually being sent.
>
> It is up to you to decide whether to use big or little endian order in

your
> messages, and convert when needed. I would decide if most of your machines

will
> be big or little endian, and then choose the most used one so that most

machines
> will not need to convert the data.


There are some really good books on TCP/IP programming that will walk you
through it. Search for things like hton and ntoh


 
Reply With Quote
 
Pascal Bourguignon
Guest
Posts: n/a

 
      09-10-2004, 05:35 AM
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Skip the PW question: I got that, question now about "Home" Tim Wilson Network Routers 1 12-31-2005 04:01 AM
Switch Question - restate previous question w/no subject SEAN J Windows Networking 2 11-30-2005 02:42 PM
Dell 2300 TrueMobile router question/ general wireless question Craig Wireless Internet 2 01-11-2004 06:26 PM



1 2 3 4 5 6 7 8 9 10 11