none
htonl source code

    Question

  • 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

    Thursday, March 16, 2006 11:31 AM

Answers

  • There is no source code for the WinSock2 stuff, as long as you don't have access to the MS source code program.
    Thursday, March 16, 2006 1:08 PM
    Moderator
  • 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.

     -Sachin wrote:

    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

    Thursday, March 16, 2006 2:59 PM
    Moderator

All replies

  • There is no source code for the WinSock2 stuff, as long as you don't have access to the MS source code program.
    Thursday, March 16, 2006 1:08 PM
    Moderator
  • 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

    Thursday, March 16, 2006 1:13 PM
  • 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.

     -Sachin wrote:

    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

    Thursday, March 16, 2006 2:59 PM
    Moderator
  • 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

    Friday, March 17, 2006 5:22 AM
  • 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

    Friday, March 17, 2006 8:56 AM
  • 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

    Friday, March 17, 2006 1:16 PM
  •  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. 

    Monday, March 27, 2006 12:53 PM