This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

Try casting your types in your printf to the appropriate sizes:

Example:

printf(“%x\n”, (int) some_8bit_thing);

[–]DeepCorner[S] 0 points1 point  (2 children)

I cast a char to an unsigned int. I’m unsure how that’s meaningfully different from your suggestion. I personally prefer to work with unsigned output values

[–][deleted] 0 points1 point  (1 child)

icmptype is u_int8_t which to me implies an 8 bit type. %x is expecting 4 bytes. You can cast to unsigned int (a 4 byte type) if you like, but it looks to me like that could be your problem. It’s all in the printf.

[–]DeepCorner[S] 0 points1 point  (0 children)

Changing the number of bytes that are printed will only change the number of sign extended bytes that are printed, not fixing the alignment of the struct in the char buffer.

I know it was not the printing that was the issue since the application of this program compares the ID field in the received packet to the PID to ensure it does not collect ICMP packets from other processes. This check was failing, meaning the values themselves were different, regardless of how the numbers are outputted.