CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: htonl function

  1. #1
    Join Date
    May 2018
    Posts
    158

    htonl function

    Lets' suppose to convert int type from host byte order to network byte order to send data to another host and I want to use htonl function.
    Host byte order depends on computer architecture (little/big-endian) so universal htonl has to knows what is MSB of my data which I wish to convert.

    Example of int
    A,B,C,D: byte
    A=MSB, D=LSB

    Big-endian:
    A B C D

    Little-endian:
    D C B A

    How does host know that MSB is on 1st position or last position to use afterwards hton function ?

  2. #2
    Join Date
    Nov 2018
    Posts
    100

    Re: htonl function

    > How does host know that MSB is on 1st position or last position to use afterwards hton function ?
    Whoever wrote the hton,,, functions for your system went and looked up the endian scheme appropriate for the processor and/or operating system relevant to the system your host is running.

    If your system is big-endian, the hton... functions just return the data as is.
    If it's little endian, there will be code in the hton... functions to do the right thing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured