From ab16e625e0bbd5012e2f69340479f02f10a5d086 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Fri, 10 Sep 2021 14:09:44 +0200 Subject: [PATCH] #6730: fix ip encoding endianness + move timespec to ffi Signed-off-by: Ludovic Orban --- .../jetty/quic/quiche/ffi/LibQuiche.java | 7 ------ .../jetty/quic/quiche/ffi/netinet_h.java | 3 ++- .../jetty/quic/quiche/ffi/timespec.java | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/timespec.java diff --git a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/LibQuiche.java b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/LibQuiche.java index 8331ade2c16..127f2f60e37 100644 --- a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/LibQuiche.java +++ b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/LibQuiche.java @@ -323,13 +323,6 @@ public interface LibQuiche extends Library public timespec at; } - @Structure.FieldOrder({"tv_sec", "tv_nsec"}) - class timespec extends Structure - { - public uint64_t tv_sec; - public long tv_nsec; - } - // Writes a single QUIC packet to be sent to the peer. ssize_t quiche_conn_send(quiche_conn conn, ByteBuffer out, size_t out_len, quiche_send_info out_info); diff --git a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/netinet_h.java b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/netinet_h.java index b84a4fc754a..ca02f2495c7 100644 --- a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/netinet_h.java +++ b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/netinet_h.java @@ -18,6 +18,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import com.sun.jna.Pointer; import com.sun.jna.Structure; @@ -37,7 +38,7 @@ public interface netinet_h sockaddr_in sa = new sockaddr_in(); sa.sin_family = AF_INET; - sa.sin_addr = new uint32_t(ByteBuffer.wrap(address.getAddress()).getInt()); // TODO: is the endianness correct? + sa.sin_addr = new uint32_t(ByteBuffer.wrap(address.getAddress()).order(ByteOrder.nativeOrder()).getInt()); sa.sin_port = new uint16_t(inetSocketAddress.getPort()); return sa; } diff --git a/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/timespec.java b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/timespec.java new file mode 100644 index 00000000000..b6ccc5da04d --- /dev/null +++ b/jetty-quic/quic-quiche/src/main/java/org/eclipse/jetty/quic/quiche/ffi/timespec.java @@ -0,0 +1,23 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.quic.quiche.ffi; + +import com.sun.jna.Structure; + +@Structure.FieldOrder({"tv_sec", "tv_nsec"}) +public class timespec extends Structure +{ + public uint64_t tv_sec; + public long tv_nsec; +}