1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.system;
18 
19 import libcore.util.NonNull;
20 import libcore.util.Nullable;
21 
22 import java.net.SocketAddress;
23 import java.nio.ByteBuffer;
24 
25 /**
26  * Corresponds to C's {@code struct msghdr}
27  *
28  */
29 public final class StructMsghdr{
30     /**
31      * Optional address.
32      * <p>Sendmsg: Caller must populate to specify the target address for a datagram, or pass
33      * {@code null} to send to the destination of an already-connected socket.
34      * Recvmsg: Populated by the system to specify the source address.
35      */
36     @Nullable public SocketAddress msg_name;
37 
38     /** Scatter/gather array */
39     @NonNull public final ByteBuffer[] msg_iov;
40 
41     /** Ancillary data */
42     @Nullable public StructCmsghdr[] msg_control;
43 
44     /** Flags on received message. */
45     public int msg_flags;
46 
47     /**
48      * Constructs an instance with the given field values
49      */
StructMsghdr(@ullable SocketAddress msg_name, @NonNull ByteBuffer[] msg_iov, @Nullable StructCmsghdr[] msg_control, int msg_flags)50     public StructMsghdr(@Nullable SocketAddress msg_name, @NonNull ByteBuffer[] msg_iov,
51                         @Nullable StructCmsghdr[] msg_control, int msg_flags) {
52         this.msg_name = msg_name;
53         this.msg_iov = msg_iov;
54         this.msg_control = msg_control;
55         this.msg_flags = msg_flags;
56     }
57 }
58