Skip to content

EncapsulateIpAddress writes wrong sin_family on big endian machine #535

@hotstreams

Description

@hotstreams

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions