1 /*
2  * Copyright (C) 2019 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.net.netlink;
18 
19 import java.nio.ByteBuffer;
20 
21 /**
22  * struct inet_diag_msg
23  *
24  * see <linux_src>/include/uapi/linux/inet_diag.h
25  *
26  * struct inet_diag_msg {
27  *      __u8    idiag_family;
28  *      __u8    idiag_state;
29  *      __u8    idiag_timer;
30  *      __u8    idiag_retrans;
31  *      struct  inet_diag_sockid id;
32  *      __u32   idiag_expires;
33  *      __u32   idiag_rqueue;
34  *      __u32   idiag_wqueue;
35  *      __u32   idiag_uid;
36  *      __u32   idiag_inode;
37  * };
38  *
39  * @hide
40  */
41 public class StructInetDiagMsg {
42     public static final int STRUCT_SIZE = 4 + StructInetDiagSockId.STRUCT_SIZE + 20;
43     private static final int IDIAG_UID_OFFSET = StructNlMsgHdr.STRUCT_SIZE + 4 +
44             StructInetDiagSockId.STRUCT_SIZE + 12;
45     public int idiag_uid;
46 
parse(ByteBuffer byteBuffer)47     public static StructInetDiagMsg parse(ByteBuffer byteBuffer) {
48         StructInetDiagMsg struct = new StructInetDiagMsg();
49         struct.idiag_uid = byteBuffer.getInt(IDIAG_UID_OFFSET);
50         return struct;
51     }
52 
53     @Override
toString()54     public String toString() {
55         return "StructInetDiagMsg{ "
56                 + "idiag_uid{" + idiag_uid + "}, "
57                 + "}";
58     }
59 }
60