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