EIPStackGroup / EIPStackGroup/OpENer

EncapsulateIpAddress writes wrong sin_family on big endian machine

Open
#535 1 comment 0 reactions 1 assignee Claimed by @MartinMelikMerkumians View on GitHub
bug
Dominant language
C
Stars
857
Forks
314
Avg merge
18d 2h
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.