Hi All,
My first ever posting. I am lookling for the sourec code for htonl, htons, ntohl etc function calls. I need to generate my own implmentation of these calls and hence need the source code for the same.
All Suggestions are welcome!!!
Thanks in advance
-Sachin

htonl source code
Clemens Vasters
A method of checking the byte order of your local machine can
be found in http://web.uccs.edu/wbahn/ECE1021/static/lessons/lesson05.htm#The%20C%20Bit%20Banging%20Bag
Basically, you have to check if the least significant byte of an unsigned integer(32-bits) is stored in the starting address of the memory location containg the value of the integer.
MichealCollins
Thanks for the prompt message.
So does that mean i cannot have my own implementation of these system calls. There must be some information as to what kind of byte ordering do these system calls make, which i can duplicate in my own function and make use of the byte ordering provided by these functions. It is very important for me to do this as there are a lot of platforms on which these calls are not supported (NetBSD to name one of them). I might be souding a bit crazy asking for this but thats all i can think of as of now to support these system calls. any other suggestion is highly welcome.
Thanks
-Sachin
Ariane Jansen
Ben Isbell
Thanks Nishant,
Well, i was hoping for the same as well as to find some source from Unix site(s) as these calls are very much supported on them. but not to any luck. Maybe i am supoosed to dig more into the Unix sites to get some help.
Thanks again.
-Sachin
Eddy Fuchs
Thats exactly the main reason why i want the source for htons etc calls so that i can write my own function which does the same set of byte ordering as done by htons/htonl etc. I am sorry if i am sounding strange but i guess i am not aware of how the htons does the byte ordering internally. all i know is that i need to use it in my code and i am not able to make use of these calls directly in my code on some unix platforms and hence am looking at creating my own implementation for the same. In case you have a sample code which explains how the byte ordering is done by these calls, it would be of great help.
Thanks in advance
-SJ
Martin Tirion - MS
Is there any reason why you must use the byte ordering provided by htonl etc Why can't you create your own byte ordering
The purpose of the functions htonl, htons etc is to make your application software portable regardless of big/small endian, msb/lsbetc.
--R
Alex Ellis
Well, you could look at the function reference to see what it does, and then you'd have to write the code on your own. You might also want to see if there are similar functions available in one of the Linux distributions - and if so, you could look at the source code - since it will be open source.