tweag/asterius

Missing `ntohs` functions

TerrorJack opened this issue · 6 comments

Describe the bug
The runtime doesn't implement ntohs functions. They're used by Network.Socket.Types in the network package, specifically, the Show instance of the SockAddr type uses them. Attempting to use it will cause a runtime crash.

EDIT: The Show SockAddr instance also depends on c_getnameinfo; this seems to be the source of the error even with ntohs implementations available. This issue shall thus be addressed when we integrate a C toolchain.

To Reproduce
Use the Show instance of SockAddr at runtime. Or transitively, the Show instance of Request from the wai package.

Expected behavior
It shouldn't crash.

Environment

  • OS name + version: Docker dev image
  • Version of the code: latest master revision

Additional context
Add any other context about the problem here.

@TerrorJack do we have currently a way to check host endianness (or, can we assume it's always little endian)? If this is just about converting from LE to BE then it shouldn't be hard to fix.

Perfect. Then byteSwap16 and byteSwap32 shall do the trick.

@TerrorJack now that I look at Network.Socket.Types more closely I think that it's not the ntohs functions that cause the failure. The Show SockAddr instance calls getNameInfo which calls c_getnameinfo; I think that c_getnameinfo is the culprit here. Can you double check?

Yes, I missed getNameInfo. Anyway, this PR is still good to go. The lack of getNameInfo and other network interfaces should be addressed in another issue/PR. Could you remove that redundant comment before merging?

Will do 👍