-
Notifications
You must be signed in to change notification settings - Fork 3
Fix htonl on 64-bit values #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@troglobit As discussed via email, here is the PR for the bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would perhaps have broken out to two helper functions marshal()/unmarshal(), but this works too.
I'm approving this, but if you want to address my inline comment before we merge this, it's up to you.
mping.c
Outdated
| if (debug) | ||
| { | ||
| struct mping packet; | ||
| printf("tv_sec size: %zu\n", sizeof(packet.tv.tv_sec)); | ||
| printf("tv_usec size: %zu\n", sizeof(packet.tv.tv_usec)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like developer debug message, maybe we can do without it? Also, notice coding style (brace placement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually overlooked the brackets because they were different in the functions.
I have now corrected this and shortened the debug output to one line.
On modern systems, time values may be stored in a 64-bit integer. To send this over the network, it is necessary to package it appropriately. htonl is insufficient for this purpose, as it is limited to 32-bit values. See also https://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c Signed-off-by: Marek Küthe <m.k@mk16.de>
You can still do that. I just adopted the existing structure. |
Signed-off-by: Marek Küthe <m.k@mk16.de>
|
I have now extracted the network encoding code into two methods. If you would like it differently, you can just merge the first commit. |
troglobit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thanks!
On modern systems, time values may be stored in a 64-bit integer. To send this over the network, it is necessary to package it appropriately. htonl is insufficient for this purpose, as it is limited to 32-bit values.
See also https://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c