1 // Generated by jextract 2 3 package jdk.internal.ffi.generated.iouring; 4 5 import java.lang.invoke.*; 6 import java.lang.foreign.*; 7 import java.nio.ByteOrder; 8 import java.util.*; 9 import java.util.function.*; 10 import java.util.stream.*; 11 12 import static java.lang.foreign.ValueLayout.*; 13 import static java.lang.foreign.MemoryLayout.PathElement.*; 14 15 /** 16 * {@snippet lang=c : 17 * struct sockaddr_in { 18 * sa_family_t sin_family; 19 * in_port_t sin_port; 20 * struct in_addr sin_addr; 21 * unsigned char sin_zero[8]; 22 * } 23 * } 24 */ 25 @SuppressWarnings("restricted") public class sockaddr_in { 26 27 sockaddr_in() { 28 // Suppresses public default constructor, ensuring non-instantiability, 29 // but allows generated subclasses in same package. 30 } 31 32 private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( 33 iouring_h.C_SHORT.withName("sin_family"), 34 iouring_h.C_SHORT.withName("sin_port"), 35 in_addr.$LAYOUT().withName("sin_addr"), 36 MemoryLayout.sequenceLayout(8, iouring_h.C_CHAR).withName("sin_zero") 37 ).withName("sockaddr_in"); 38 39 public static final GroupLayout $LAYOUT() { 40 return $LAYOUT; 41 } 42 43 private static final long sin_family$OFFSET = 0; 44 private static final OfShort sin_family$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sin_family")); 45 46 /** 47 * Getter for field: 48 * {@snippet lang=c : 49 * sa_family_t sin_family 50 * } 51 */ 52 public static short sin_family(MemorySegment struct) { 53 return struct.get(sin_family$LAYOUT, sin_family$OFFSET); 54 } 55 56 /** 57 * Setter for field: 58 * {@snippet lang=c : 59 * sa_family_t sin_family 60 * } 61 */ 62 public static void sin_family(MemorySegment struct, short fieldValue) { 63 struct.set(sin_family$LAYOUT, sin_family$OFFSET, fieldValue); 64 } 65 66 private static final long sin_port$OFFSET = 2; 67 private static final OfShort sin_port$LAYOUT = ((OfShort)$LAYOUT.select(groupElement("sin_port"))).withOrder(ByteOrder.BIG_ENDIAN); 68 69 /** 70 * Getter for field: 71 * {@snippet lang=c : 72 * in_port_t sin_port 73 * } 74 */ 75 public static short sin_port(MemorySegment struct) { 76 return struct.get(sin_port$LAYOUT, sin_port$OFFSET); 77 } 78 79 /** 80 * Setter for field: 81 * {@snippet lang=c : 82 * in_port_t sin_port 83 * } 84 */ 85 public static void sin_port(MemorySegment struct, short fieldValue) { 86 struct.set(sin_port$LAYOUT, sin_port$OFFSET, fieldValue); 87 } 88 89 private static final long sin_addr$OFFSET = 4; 90 private static final long sin_addr$SIZE = 4; 91 92 /** 93 * Getter for field: 94 * {@snippet lang=c : 95 * struct in_addr sin_addr 96 * } 97 */ 98 public static MemorySegment sin_addr(MemorySegment struct) { 99 return struct.asSlice(sin_addr$OFFSET, sin_addr$SIZE); 100 } 101 102 /** 103 * Setter for field: 104 * {@snippet lang=c : 105 * struct in_addr sin_addr 106 * } 107 */ 108 public static void sin_addr(MemorySegment struct, MemorySegment fieldValue) { 109 MemorySegment.copy(fieldValue, 0L, struct, sin_addr$OFFSET, sin_addr$SIZE); 110 } 111 112 private static final long sin_zero$OFFSET = 8; 113 private static final long sin_zero$SIZE = 8; 114 115 /** 116 * Getter for field: 117 * {@snippet lang=c : 118 * unsigned char sin_zero[8] 119 * } 120 */ 121 public static MemorySegment sin_zero(MemorySegment struct) { 122 return struct.asSlice(sin_zero$OFFSET, sin_zero$SIZE); 123 } 124 125 /** 126 * Setter for field: 127 * {@snippet lang=c : 128 * unsigned char sin_zero[8] 129 * } 130 */ 131 public static void sin_zero(MemorySegment struct, MemorySegment fieldValue) { 132 MemorySegment.copy(fieldValue, 0L, struct, sin_zero$OFFSET, sin_zero$SIZE); 133 } 134 135 public static MemorySegment asSlice(MemorySegment array, long index) { 136 return array.asSlice($LAYOUT().byteSize() * index); 137 } 138 139 public static long sizeof() { return $LAYOUT().byteSize(); } 140 141 public static MemorySegment allocate(SegmentAllocator allocator) { 142 return allocator.allocate($LAYOUT()); 143 } 144 145 public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { 146 return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, $LAYOUT())); 147 } 148 149 public static MemorySegment reinterpret(MemorySegment addr, Arena scope, Consumer<MemorySegment> cleanup) { 150 return reinterpret(addr, 1, scope, cleanup); 151 } 152 153 public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena scope, Consumer<MemorySegment> cleanup) { 154 return addr.reinterpret($LAYOUT().byteSize() * elementCount, scope, cleanup); 155 } 156 } 157