OpENer icon indicating copy to clipboard operation
OpENer copied to clipboard

EncapsulateIpAddress writes wrong sin_family on big endian machine

Open hotstreams opened this issue 5 months ago • 0 comments

I was compiling and using the same OpENer server on both little-endian and big-endian machines, and found out that response packet for Forward Open Request differs.

Wireshark logs:

ubuntu 24:

Image

openwrt: Image

I started digging around and came across this function:

https://github.com/EIPStackGroup/OpENer/blob/db1d6bfbd6cdc216944e03326167c19a5ff675d0/source/src/enet_encap/endianconv.c#L201C1-L228C2

The problem is AddIntToMessage(htons(AF_INET), outgoing_message) which writes value (not internal memory representation) byte by byte in little-endian order.

AddIntToMessage(htons(AF_INET), outgoing_message);

But the value htons(AF_INET) for big-endian stays the same and not gets converted.

It should be

AddSintToMessage(AF_INET >> 8, outgoing_message);
AddSintToMessage(AF_INET, outgoing_message);

which fixes the problem and it works.

hotstreams avatar Aug 22 '25 09:08 hotstreams