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

me.bechberger.ebpf.bpf.raw.sockaddr_in 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 sockaddr_in {
 *     __kernel_sa_family_t sin_family;
 *     __be16 sin_port;
 *     struct in_addr sin_addr;
 *     unsigned char __pad[8];
 * }
 * }
 */
public class sockaddr_in {

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

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        Lib.C_SHORT.withName("sin_family"),
        Lib.C_SHORT.withName("sin_port"),
        in_addr.layout().withName("sin_addr"),
        MemoryLayout.sequenceLayout(8, Lib.C_CHAR).withName("__pad")
    ).withName("sockaddr_in");

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

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

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

    private static final long sin_family$OFFSET = 0;

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

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

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

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

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

    private static final long sin_port$OFFSET = 2;

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

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

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

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

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

    private static final long sin_addr$OFFSET = 4;

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

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

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

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

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static final SequenceLayout __pad$layout() {
        return __pad$LAYOUT;
    }

    private static final long __pad$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static final long __pad$offset() {
        return __pad$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static MemorySegment __pad(MemorySegment struct) {
        return struct.asSlice(__pad$OFFSET, __pad$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static void __pad(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, __pad$OFFSET, __pad$LAYOUT.byteSize());
    }

    private static long[] __pad$DIMS = { 8 };

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

    /**
     * Indexed getter for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static byte __pad(MemorySegment struct, long index0) {
        return (byte)__pad$ELEM_HANDLE.get(struct, 0L, index0);
    }

    /**
     * Indexed setter for field:
     * {@snippet lang=c :
     * unsigned char __pad[8]
     * }
     */
    public static void __pad(MemorySegment struct, long index0, byte fieldValue) {
        __pad$ELEM_HANDLE.set(struct, 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 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