Re: 64-bit network byte order

Roland Dowdeswell <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Organization The Fall of Imrryr
Message-ID <[email protected]>
On 1019599649 seconds since the Beginning of the UNIX epoch
chintan sheth wrote:
>
>> Hi,
>> 
>> What will be the network byte order value of the
>> following 64 bit value:
>> 
>>         0000 02c1 1001 0002
>> 
>> Kindly reply asap.

Sure:  this is an inspecific question since you have not stated what
byte order the original value is in.  Two byte orders are prevalent on
most hardware that is available today, little endian and big endian.
Network byte order is big endian.  If you don't know the byte order,
run the following little program:

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/endian.h>

void
usage()
{
	fprintf(stderr, "usage: tonetworkbyteorder <num>\n");
	exit(1);
}

int
main(int argc, char **argv)
{
	u_int64_t	num;

	if (argc != 2)
		usage();

	/* okay, okay, u_quad_t may not be u_int64_t... */
	num = strtouq(*++argv, NULL, 0);
	HTOBE64(num);
	printf("in network byte order: %qx\n", num);
}

As an aside, these three mailing lists may not actually be entirely
appropriate for this kind of vanilla computer question.

 == Roland Dowdeswell                      http://www.Imrryr.ORG/~elric/  ==
 == The Unofficial NetBSD Web Pages        http://www.Imrryr.ORG/NetBSD/  ==
 == The NetBSD Project                            http://www.NetBSD.ORG/  ==
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.