All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.bechberger.ebpf.bpf.raw.icmphdr Maven / Gradle / Ivy

The newest version!
// Generated by jextract

package me.bechberger.ebpf.bpf.raw;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct icmphdr {
 *     __u8 type;
 *     __u8 code;
 *     __sum16 checksum;
 *     union {
 *         struct {
 *             __be16 id;
 *             __be16 sequence;
 *         } echo;
 *         __be32 gateway;
 *         struct {
 *             __be16 __unused;
 *             __be16 mtu;
 *         } frag;
 *         __u8 reserved[4];
 *     } un;
 * }
 * }
 */
public class icmphdr {

    icmphdr() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        Lib.C_CHAR.withName("type"),
        Lib.C_CHAR.withName("code"),
        Lib.C_SHORT.withName("checksum"),
        icmphdr.un.layout().withName("un")
    ).withName("icmphdr");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfByte type$LAYOUT = (OfByte)$LAYOUT.select(groupElement("type"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u8 type
     * }
     */
    public static final OfByte type$layout() {
        return type$LAYOUT;
    }

    private static final long type$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u8 type
     * }
     */
    public static final long type$offset() {
        return type$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u8 type
     * }
     */
    public static byte type(MemorySegment struct) {
        return struct.get(type$LAYOUT, type$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u8 type
     * }
     */
    public static void type(MemorySegment struct, byte fieldValue) {
        struct.set(type$LAYOUT, type$OFFSET, fieldValue);
    }

    private static final OfByte code$LAYOUT = (OfByte)$LAYOUT.select(groupElement("code"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u8 code
     * }
     */
    public static final OfByte code$layout() {
        return code$LAYOUT;
    }

    private static final long code$OFFSET = 1;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u8 code
     * }
     */
    public static final long code$offset() {
        return code$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u8 code
     * }
     */
    public static byte code(MemorySegment struct) {
        return struct.get(code$LAYOUT, code$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u8 code
     * }
     */
    public static void code(MemorySegment struct, byte fieldValue) {
        struct.set(code$LAYOUT, code$OFFSET, fieldValue);
    }

    private static final OfShort checksum$LAYOUT = (OfShort)$LAYOUT.select(groupElement("checksum"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __sum16 checksum
     * }
     */
    public static final OfShort checksum$layout() {
        return checksum$LAYOUT;
    }

    private static final long checksum$OFFSET = 2;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __sum16 checksum
     * }
     */
    public static final long checksum$offset() {
        return checksum$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __sum16 checksum
     * }
     */
    public static short checksum(MemorySegment struct) {
        return struct.get(checksum$LAYOUT, checksum$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __sum16 checksum
     * }
     */
    public static void checksum(MemorySegment struct, short fieldValue) {
        struct.set(checksum$LAYOUT, checksum$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * union {
     *     struct {
     *         __be16 id;
     *         __be16 sequence;
     *     } echo;
     *     __be32 gateway;
     *     struct {
     *         __be16 __unused;
     *         __be16 mtu;
     *     } frag;
     *     __u8 reserved[4];
     * }
     * }
     */
    public static class un {

        un() {
            // Should not be called directly
        }

        private static final GroupLayout $LAYOUT = MemoryLayout.unionLayout(
            icmphdr.un.echo.layout().withName("echo"),
            Lib.C_INT.withName("gateway"),
            icmphdr.un.frag.layout().withName("frag"),
            MemoryLayout.sequenceLayout(4, Lib.C_CHAR).withName("reserved")
        ).withName("$anon$93:3");

        /**
         * The layout of this union
         */
        public static final GroupLayout layout() {
            return $LAYOUT;
        }

        /**
         * {@snippet lang=c :
         * struct {
         *     __be16 id;
         *     __be16 sequence;
         * }
         * }
         */
        public static class echo {

            echo() {
                // Should not be called directly
            }

            private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
                Lib.C_SHORT.withName("id"),
                Lib.C_SHORT.withName("sequence")
            ).withName("$anon$94:2");

            /**
             * The layout of this struct
             */
            public static final GroupLayout layout() {
                return $LAYOUT;
            }

            private static final OfShort id$LAYOUT = (OfShort)$LAYOUT.select(groupElement("id"));

            /**
             * Layout for field:
             * {@snippet lang=c :
             * __be16 id
             * }
             */
            public static final OfShort id$layout() {
                return id$LAYOUT;
            }

            private static final long id$OFFSET = 0;

            /**
             * Offset for field:
             * {@snippet lang=c :
             * __be16 id
             * }
             */
            public static final long id$offset() {
                return id$OFFSET;
            }

            /**
             * Getter for field:
             * {@snippet lang=c :
             * __be16 id
             * }
             */
            public static short id(MemorySegment struct) {
                return struct.get(id$LAYOUT, id$OFFSET);
            }

            /**
             * Setter for field:
             * {@snippet lang=c :
             * __be16 id
             * }
             */
            public static void id(MemorySegment struct, short fieldValue) {
                struct.set(id$LAYOUT, id$OFFSET, fieldValue);
            }

            private static final OfShort sequence$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sequence"));

            /**
             * Layout for field:
             * {@snippet lang=c :
             * __be16 sequence
             * }
             */
            public static final OfShort sequence$layout() {
                return sequence$LAYOUT;
            }

            private static final long sequence$OFFSET = 2;

            /**
             * Offset for field:
             * {@snippet lang=c :
             * __be16 sequence
             * }
             */
            public static final long sequence$offset() {
                return sequence$OFFSET;
            }

            /**
             * Getter for field:
             * {@snippet lang=c :
             * __be16 sequence
             * }
             */
            public static short sequence(MemorySegment struct) {
                return struct.get(sequence$LAYOUT, sequence$OFFSET);
            }

            /**
             * Setter for field:
             * {@snippet lang=c :
             * __be16 sequence
             * }
             */
            public static void sequence(MemorySegment struct, short fieldValue) {
                struct.set(sequence$LAYOUT, sequence$OFFSET, fieldValue);
            }

            /**
             * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
             * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
             */
            public static MemorySegment asSlice(MemorySegment array, long index) {
                return array.asSlice(layout().byteSize() * index);
            }

            /**
             * The size (in bytes) of this struct
             */
            public static long sizeof() { return layout().byteSize(); }

            /**
             * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
             */
            public static MemorySegment allocate(SegmentAllocator allocator) {
                return allocator.allocate(layout());
            }

            /**
             * Allocate an array of size {@code elementCount} using {@code allocator}.
             * The returned segment has size {@code elementCount * layout().byteSize()}.
             */
            public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
                return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
            }

            /**
             * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
             * The returned segment has size {@code layout().byteSize()}
             */
            public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
                return reinterpret(addr, 1, arena, cleanup);
            }

            /**
             * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
             * The returned segment has size {@code elementCount * layout().byteSize()}
             */
            public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
                return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
            }
        }

        private static final GroupLayout echo$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("echo"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 id;
         *     __be16 sequence;
         * } echo
         * }
         */
        public static final GroupLayout echo$layout() {
            return echo$LAYOUT;
        }

        private static final long echo$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 id;
         *     __be16 sequence;
         * } echo
         * }
         */
        public static final long echo$offset() {
            return echo$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 id;
         *     __be16 sequence;
         * } echo
         * }
         */
        public static MemorySegment echo(MemorySegment union) {
            return union.asSlice(echo$OFFSET, echo$LAYOUT.byteSize());
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 id;
         *     __be16 sequence;
         * } echo
         * }
         */
        public static void echo(MemorySegment union, MemorySegment fieldValue) {
            MemorySegment.copy(fieldValue, 0L, union, echo$OFFSET, echo$LAYOUT.byteSize());
        }

        private static final OfInt gateway$LAYOUT = (OfInt)$LAYOUT.select(groupElement("gateway"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * __be32 gateway
         * }
         */
        public static final OfInt gateway$layout() {
            return gateway$LAYOUT;
        }

        private static final long gateway$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * __be32 gateway
         * }
         */
        public static final long gateway$offset() {
            return gateway$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * __be32 gateway
         * }
         */
        public static int gateway(MemorySegment union) {
            return union.get(gateway$LAYOUT, gateway$OFFSET);
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * __be32 gateway
         * }
         */
        public static void gateway(MemorySegment union, int fieldValue) {
            union.set(gateway$LAYOUT, gateway$OFFSET, fieldValue);
        }

        /**
         * {@snippet lang=c :
         * struct {
         *     __be16 __unused;
         *     __be16 mtu;
         * }
         * }
         */
        public static class frag {

            frag() {
                // Should not be called directly
            }

            private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
                Lib.C_SHORT.withName("__unused"),
                Lib.C_SHORT.withName("mtu")
            ).withName("$anon$99:2");

            /**
             * The layout of this struct
             */
            public static final GroupLayout layout() {
                return $LAYOUT;
            }

            private static final OfShort __unused$LAYOUT = (OfShort)$LAYOUT.select(groupElement("__unused"));

            /**
             * Layout for field:
             * {@snippet lang=c :
             * __be16 __unused
             * }
             */
            public static final OfShort __unused$layout() {
                return __unused$LAYOUT;
            }

            private static final long __unused$OFFSET = 0;

            /**
             * Offset for field:
             * {@snippet lang=c :
             * __be16 __unused
             * }
             */
            public static final long __unused$offset() {
                return __unused$OFFSET;
            }

            /**
             * Getter for field:
             * {@snippet lang=c :
             * __be16 __unused
             * }
             */
            public static short __unused(MemorySegment struct) {
                return struct.get(__unused$LAYOUT, __unused$OFFSET);
            }

            /**
             * Setter for field:
             * {@snippet lang=c :
             * __be16 __unused
             * }
             */
            public static void __unused(MemorySegment struct, short fieldValue) {
                struct.set(__unused$LAYOUT, __unused$OFFSET, fieldValue);
            }

            private static final OfShort mtu$LAYOUT = (OfShort)$LAYOUT.select(groupElement("mtu"));

            /**
             * Layout for field:
             * {@snippet lang=c :
             * __be16 mtu
             * }
             */
            public static final OfShort mtu$layout() {
                return mtu$LAYOUT;
            }

            private static final long mtu$OFFSET = 2;

            /**
             * Offset for field:
             * {@snippet lang=c :
             * __be16 mtu
             * }
             */
            public static final long mtu$offset() {
                return mtu$OFFSET;
            }

            /**
             * Getter for field:
             * {@snippet lang=c :
             * __be16 mtu
             * }
             */
            public static short mtu(MemorySegment struct) {
                return struct.get(mtu$LAYOUT, mtu$OFFSET);
            }

            /**
             * Setter for field:
             * {@snippet lang=c :
             * __be16 mtu
             * }
             */
            public static void mtu(MemorySegment struct, short fieldValue) {
                struct.set(mtu$LAYOUT, mtu$OFFSET, fieldValue);
            }

            /**
             * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
             * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
             */
            public static MemorySegment asSlice(MemorySegment array, long index) {
                return array.asSlice(layout().byteSize() * index);
            }

            /**
             * The size (in bytes) of this struct
             */
            public static long sizeof() { return layout().byteSize(); }

            /**
             * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
             */
            public static MemorySegment allocate(SegmentAllocator allocator) {
                return allocator.allocate(layout());
            }

            /**
             * Allocate an array of size {@code elementCount} using {@code allocator}.
             * The returned segment has size {@code elementCount * layout().byteSize()}.
             */
            public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
                return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
            }

            /**
             * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
             * The returned segment has size {@code layout().byteSize()}
             */
            public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
                return reinterpret(addr, 1, arena, cleanup);
            }

            /**
             * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
             * The returned segment has size {@code elementCount * layout().byteSize()}
             */
            public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
                return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
            }
        }

        private static final GroupLayout frag$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("frag"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 __unused;
         *     __be16 mtu;
         * } frag
         * }
         */
        public static final GroupLayout frag$layout() {
            return frag$LAYOUT;
        }

        private static final long frag$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 __unused;
         *     __be16 mtu;
         * } frag
         * }
         */
        public static final long frag$offset() {
            return frag$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 __unused;
         *     __be16 mtu;
         * } frag
         * }
         */
        public static MemorySegment frag(MemorySegment union) {
            return union.asSlice(frag$OFFSET, frag$LAYOUT.byteSize());
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * struct {
         *     __be16 __unused;
         *     __be16 mtu;
         * } frag
         * }
         */
        public static void frag(MemorySegment union, MemorySegment fieldValue) {
            MemorySegment.copy(fieldValue, 0L, union, frag$OFFSET, frag$LAYOUT.byteSize());
        }

        private static final SequenceLayout reserved$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("reserved"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static final SequenceLayout reserved$layout() {
            return reserved$LAYOUT;
        }

        private static final long reserved$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static final long reserved$offset() {
            return reserved$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static MemorySegment reserved(MemorySegment union) {
            return union.asSlice(reserved$OFFSET, reserved$LAYOUT.byteSize());
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static void reserved(MemorySegment union, MemorySegment fieldValue) {
            MemorySegment.copy(fieldValue, 0L, union, reserved$OFFSET, reserved$LAYOUT.byteSize());
        }

        private static long[] reserved$DIMS = { 4 };

        /**
         * Dimensions for array field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static long[] reserved$dimensions() {
            return reserved$DIMS;
        }
        private static final VarHandle reserved$ELEM_HANDLE = reserved$LAYOUT.varHandle(sequenceElement());

        /**
         * Indexed getter for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static byte reserved(MemorySegment union, long index0) {
            return (byte)reserved$ELEM_HANDLE.get(union, 0L, index0);
        }

        /**
         * Indexed setter for field:
         * {@snippet lang=c :
         * __u8 reserved[4]
         * }
         */
        public static void reserved(MemorySegment union, long index0, byte fieldValue) {
            reserved$ELEM_HANDLE.set(union, 0L, index0, fieldValue);
        }

        /**
         * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
         * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
         */
        public static MemorySegment asSlice(MemorySegment array, long index) {
            return array.asSlice(layout().byteSize() * index);
        }

        /**
         * The size (in bytes) of this union
         */
        public static long sizeof() { return layout().byteSize(); }

        /**
         * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
         */
        public static MemorySegment allocate(SegmentAllocator allocator) {
            return allocator.allocate(layout());
        }

        /**
         * Allocate an array of size {@code elementCount} using {@code allocator}.
         * The returned segment has size {@code elementCount * layout().byteSize()}.
         */
        public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
            return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
            return reinterpret(addr, 1, arena, cleanup);
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code elementCount * layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
            return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
        }
    }

    private static final GroupLayout un$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("un"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * union {
     *     struct {
     *         __be16 id;
     *         __be16 sequence;
     *     } echo;
     *     __be32 gateway;
     *     struct {
     *         __be16 __unused;
     *         __be16 mtu;
     *     } frag;
     *     __u8 reserved[4];
     * } un
     * }
     */
    public static final GroupLayout un$layout() {
        return un$LAYOUT;
    }

    private static final long un$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * union {
     *     struct {
     *         __be16 id;
     *         __be16 sequence;
     *     } echo;
     *     __be32 gateway;
     *     struct {
     *         __be16 __unused;
     *         __be16 mtu;
     *     } frag;
     *     __u8 reserved[4];
     * } un
     * }
     */
    public static final long un$offset() {
        return un$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * union {
     *     struct {
     *         __be16 id;
     *         __be16 sequence;
     *     } echo;
     *     __be32 gateway;
     *     struct {
     *         __be16 __unused;
     *         __be16 mtu;
     *     } frag;
     *     __u8 reserved[4];
     * } un
     * }
     */
    public static MemorySegment un(MemorySegment struct) {
        return struct.asSlice(un$OFFSET, un$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * union {
     *     struct {
     *         __be16 id;
     *         __be16 sequence;
     *     } echo;
     *     __be32 gateway;
     *     struct {
     *         __be16 __unused;
     *         __be16 mtu;
     *     } frag;
     *     __u8 reserved[4];
     * } un
     * }
     */
    public static void un(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, un$OFFSET, un$LAYOUT.byteSize());
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy