Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Oct 2001 08:53:11 -0800
From:      Bakul Shah <bakul@bitblocks.com>
To:        tlambert2@mindspring.com
Cc:        Fabio Miranda <fmirand@yahoo.com>, freebsd-chat@FreeBSD.org
Subject:   Re: offtopic: c questions 
Message-ID:  <200110301653.LAA13598@goliath.cnchost.com>
In-Reply-To: Your message of "Sat, 27 Oct 2001 12:09:52 PDT." <3BDB0680.E8714908@mindspring.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > hi, I am freebsd user, i want to know:
> > 1. I would like to understand network byte ordering
> > concepts. I know some machines are "little endian" and
> > "big endian", and tcpip provides a standard called
> > network ordering throught htonl, htons,etc fuctions.
> > I want to know How does look like bigendians and
> > network byte ordering?, how can i know if i am in a
> > little or bigendian host?
> 
> It has to do with whether the most significant bit of a
> multibyte value is in the first byte or the last byte,
> when a multibyte value is converted to a stream of
> bytes on a network transport.
> 
> It is a corruption of whether you put "the big end in to
> the pipe first, or the little end in", combined with a
> joke on the English similarity in pronunciation between
> the word pair "end in" and the word "Indian" -- hence the
> use of the "a" in the contration: "endian" instead of
> "endin".

Terry, I am surprised you didn't cite `On holy wars and a
plea for peace' by Danny Cohen (USC/ISI IEN 137) which is
where the computer related use of the big/little endian terms
started.  There are copies floating around on the net.  At
any rate I doubt Jonathan Swift had Indians in mind when he
coined these terms in Gulliver's Travels.

> Network byte order is Motorolla byte order, which is the
> opposite of that of the x86 architecture.

Network byte order is big endian.  Also note that the network
*bit* order is big endian as well (as can be seen by looking
at any packet layout in various RFCs), while Motorola and
most all big endian machines use little endian bit order
(bit0 == LSB, bit31 == MSB).  Intel machines are pure little
endian.  To add to the confusion, usually the first
*transmitted* bit is LSB of the first (and most significant)
byte!

One can know the host endianness by this trick:

long x = 0x30313233;
int
main(int c,char*v)
{
	printf("%s endian\n", memcmp(&x, "0123", 4)? "little" : "big");
}

Basically we are checking (for big endianness) if byte0 of x
is '0', byte1 is '1' and so on.

> > 2. I am student of computer science, but at my
> > university noone use freebsd or  code bsd socket, so,
> > i am doing this by my own, but it's hard, i read
> > commer book about tcpip, but, i dont understand the
> > concepts, i have printed almost all freebsd man
> > related to sockets. I would like to know  what way did
> > you guy follow to understand tpcip understand unix?, i
> > dont have money to buy a book at amazon, but, is that
> > the only way? can't i understand unix tcpip
> > programming with free resources?
> 
> Read the Richard Stevens books instead of the Comer book.

A quick Google search for 'tcp/ip programming tutorial'
revealed
  http://www.ecst.csuchico.edu/~beej/guide/net/
Not a substitute for Stevens' books but it is free!  There
may be other resources on the net.  Regardless of what books
Fabio reads he should also study working code (ttcp for
example) and _write_ lots of code.  It is the "doing of" not
"reading about" something that leads to enlightenment.  Finally
I can resisting suggesting that Fabio should consider moving
to plan9 -- a far simpler & cleaner system brought to you by
Bell Labs (where unix originated) and a joy to use.
plan9.bell-labs.com and www.fywss.con/plan9 are a couple of
good starting points.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110301653.LAA13598>