NetlinkErrorMessage.java revision 6193aa3305bc2aa5b7f0a983f4b08c99065cfb82
1/*
2 * Copyright (C) 2015 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
17package android.net.netlink;
18
19import android.net.netlink.StructNlMsgHdr;
20import android.net.netlink.NetlinkMessage;
21import android.util.Log;
22
23import java.nio.ByteBuffer;
24
25
26/**
27 * A NetlinkMessage subclass for netlink error messages.
28 *
29 * @hide
30 */
31public class NetlinkErrorMessage extends NetlinkMessage {
32
33    public static NetlinkErrorMessage parse(StructNlMsgHdr header, ByteBuffer byteBuffer) {
34        final NetlinkErrorMessage errorMsg = new NetlinkErrorMessage(header);
35
36        errorMsg.mNlMsgErr = StructNlMsgErr.parse(byteBuffer);
37        if (errorMsg.mNlMsgErr == null) {
38            return null;
39        }
40
41        return errorMsg;
42    }
43
44    private StructNlMsgErr mNlMsgErr;
45
46    NetlinkErrorMessage(StructNlMsgHdr header) {
47        super(header);
48        mNlMsgErr = null;
49    }
50
51    public StructNlMsgErr getNlMsgError() {
52        return mNlMsgErr;
53    }
54
55    @Override
56    public String toString() {
57        return "NetlinkErrorMessage{ "
58                + "nlmsghdr{" + (mHeader == null ? "" : mHeader.toString()) + "}, "
59                + "nlmsgerr{" + (mNlMsgErr == null ? "" : mNlMsgErr.toString()) + "} "
60                + "}";
61    }
62}
63