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 /**
23  * A NetlinkMessage subclass for netlink error messages.
24  *
25  * @hide
26  */
27 public class NetlinkErrorMessage extends NetlinkMessage {
28 
parse(StructNlMsgHdr header, ByteBuffer byteBuffer)29     public static NetlinkErrorMessage parse(StructNlMsgHdr header, ByteBuffer byteBuffer) {
30         final NetlinkErrorMessage errorMsg = new NetlinkErrorMessage(header);
31 
32         errorMsg.mNlMsgErr = StructNlMsgErr.parse(byteBuffer);
33         if (errorMsg.mNlMsgErr == null) {
34             return null;
35         }
36 
37         return errorMsg;
38     }
39 
40     private StructNlMsgErr mNlMsgErr;
41 
NetlinkErrorMessage(StructNlMsgHdr header)42     NetlinkErrorMessage(StructNlMsgHdr header) {
43         super(header);
44         mNlMsgErr = null;
45     }
46 
getNlMsgError()47     public StructNlMsgErr getNlMsgError() {
48         return mNlMsgErr;
49     }
50 
51     @Override
toString()52     public String toString() {
53         return "NetlinkErrorMessage{ "
54                 + "nlmsghdr{" + (mHeader == null ? "" : mHeader.toString()) + "}, "
55                 + "nlmsgerr{" + (mNlMsgErr == null ? "" : mNlMsgErr.toString()) + "} "
56                 + "}";
57     }
58 }
59