blob: b30470a2f1f03509c13b28a4e74b60fc9766056f [file] [log] [blame]
Mingguang Xu2d87c612021-10-29 00:18:55 -07001/*
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
17package android.net;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
Mingguang Xu6914a162022-01-26 15:37:57 -080021import android.annotation.SuppressLint;
Mingguang Xu2d87c612021-10-29 00:18:55 -070022import android.annotation.SystemApi;
23import android.os.Parcel;
24import android.os.Parcelable;
25
26/**
27 * A class representing an option in the DHCP protocol.
28 *
29 * @hide
30 */
31@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
32public final class DhcpOption implements Parcelable {
33 private final byte mType;
34 private final byte[] mValue;
35
36 /**
37 * Constructs a DhcpOption object.
38 *
Mingguang Xu6914a162022-01-26 15:37:57 -080039 * @param type the type of this option. For more information, see
40 * https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml.
Mingguang Xu2d87c612021-10-29 00:18:55 -070041 * @param value the value of this option. If {@code null}, DHCP packets containing this option
42 * will include the option type in the Parameter Request List. Otherwise, DHCP
43 * packets containing this option will include the option in the options section.
44 */
Mingguang Xu6914a162022-01-26 15:37:57 -080045 public DhcpOption(@SuppressLint("NoByteOrShort") byte type, @Nullable byte[] value) {
Mingguang Xu2d87c612021-10-29 00:18:55 -070046 mType = type;
47 mValue = value;
48 }
49
50 @Override
51 public int describeContents() {
52 return 0;
53 }
54
55 @Override
56 public void writeToParcel(@NonNull Parcel dest, int flags) {
57 dest.writeByte(mType);
58 dest.writeByteArray(mValue);
59 }
60
61 /** Implement the Parcelable interface */
62 public static final @NonNull Creator<DhcpOption> CREATOR =
63 new Creator<DhcpOption>() {
64 public DhcpOption createFromParcel(Parcel in) {
65 return new DhcpOption(in.readByte(), in.createByteArray());
66 }
67
68 public DhcpOption[] newArray(int size) {
69 return new DhcpOption[size];
70 }
71 };
72
73 /** Get the type of DHCP option */
Mingguang Xu6914a162022-01-26 15:37:57 -080074 @SuppressLint("NoByteOrShort")
Mingguang Xu2d87c612021-10-29 00:18:55 -070075 public byte getType() {
76 return mType;
77 }
78
79 /** Get the value of DHCP option */
80 @Nullable public byte[] getValue() {
81 return mValue == null ? null : mValue.clone();
82 }
83}