-
September 23rd, 2023, 03:34 AM
#1
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 ?
-
September 23rd, 2023, 03:57 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|