Skip to content

Commit

Permalink
feat(#3251): inet_addr in big endian
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Sep 25, 2024
1 parent 078dce2 commit 3b83c77
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public Phi make(final Phi... params) {
final Phi result = this.posix.take("return").copy();
result.put(
0,
new Data.ToPhi(CStdLib.INSTANCE.inet_addr(new Dataized(params[0]).asString()))
new Data.ToPhi(
Integer.reverseBytes(
CStdLib.INSTANCE.inet_addr(new Dataized(params[0]).asString())
)
)
);
result.put(1, new PhDefault());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public Phi make(final Phi... params) {
final Phi result = this.win.take("return").copy();
result.put(
0,
new Data.ToPhi(Winsock.INSTANCE.inet_addr(new Dataized(params[0]).asString()))
new Data.ToPhi(
Integer.reverseBytes(
Winsock.INSTANCE.inet_addr(new Dataized(params[0]).asString())
)
)
);
result.put(1, new PhDefault());
return result;
Expand Down
10 changes: 10 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/sys/posix-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@
"close"
* sd
-1

# Test.
[] > returns-valid-posix-inet-addr-for-localhost
code. > addr
posix
"inet_addr"
* "127.0.0.1"
or. > @
os.is-windows
addr.eq 2130706433
10 changes: 10 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/sys/win32-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@
and.
called.code
called.output.eq msg.size

# Test.
[] > returns-valid-win32-inet-addr-for-localhost
code. > addr
win32
"inet_addr"
* "127.0.0.1"
or. > @
os.is-windows.not
addr.eq 2130706433
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class EOsocketTest {
/**
* Localhost IP.
*/
private static String LOCALHOST = "127.0.0.1";
private static final String LOCALHOST = "127.0.0.1";

@Test
@DisabledOnOs(OS.WINDOWS)
Expand All @@ -79,7 +79,7 @@ void connectsToLocalServerViaPosixSyscall() throws IOException {
final SockaddrIn addr = new SockaddrIn(
(short) CStdLib.AF_INET,
EOsocketTest.htons(8080),
CStdLib.INSTANCE.inet_addr(EOsocketTest.LOCALHOST)
Integer.reverseBytes(CStdLib.INSTANCE.inet_addr(EOsocketTest.LOCALHOST))
);
final int connected = CStdLib.INSTANCE.connect(socket, addr, addr.size());
final String error;
Expand Down Expand Up @@ -107,7 +107,7 @@ void connectsToLocalServerViaWindowsSyscall() throws IOException {
assert Winsock.INSTANCE.WSAStartup(
Winsock.WINSOCK_VERSION_2_2,
new WSAStartupFuncCall.WSAData()
) > 0;
) == 0;
final int socket = Winsock.INSTANCE.socket(
Winsock.AF_INET,
Winsock.SOCK_STREAM,
Expand All @@ -117,7 +117,7 @@ void connectsToLocalServerViaWindowsSyscall() throws IOException {
final SockaddrIn addr = new SockaddrIn(
(short) Winsock.AF_INET,
EOsocketTest.htons(8080),
Winsock.INSTANCE.inet_addr(EOsocketTest.LOCALHOST)
Integer.reverseBytes(Winsock.INSTANCE.inet_addr(EOsocketTest.LOCALHOST))
);
final int connected = Winsock.INSTANCE.connect(socket, addr, addr.size());
final int error;
Expand Down

0 comments on commit 3b83c77

Please sign in to comment.