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.system;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 
21 import java.net.SocketAddress;
22 import libcore.util.Objects;
23 
24 /**
25  * Netlink socket address.
26  *
27  * Corresponds to Linux's {@code struct sockaddr_nl} from
28  * <a href="https://github.com/torvalds/linux/blob/master/include/uapi/linux/netlink.h">&lt;linux/netlink.h&gt;</a>.
29  *
30  * @hide
31  */
32 @libcore.api.CorePlatformApi
33 public final class NetlinkSocketAddress extends SocketAddress {
34     /** port ID */
35     private final int nlPortId;
36 
37     /** multicast groups mask */
38     private final int nlGroupsMask;
39 
NetlinkSocketAddress()40     public NetlinkSocketAddress() {
41         this(0, 0);
42     }
43 
NetlinkSocketAddress(int nlPortId)44     public NetlinkSocketAddress(int nlPortId) {
45         this(nlPortId, 0);
46     }
47 
48     @UnsupportedAppUsage
49     @libcore.api.CorePlatformApi
NetlinkSocketAddress(int nlPortId, int nlGroupsMask)50     public NetlinkSocketAddress(int nlPortId, int nlGroupsMask) {
51         this.nlPortId = nlPortId;
52         this.nlGroupsMask = nlGroupsMask;
53     }
54 
55     @libcore.api.CorePlatformApi
getPortId()56     public int getPortId() {
57         return nlPortId;
58     }
59 
60     @libcore.api.CorePlatformApi
getGroupsMask()61     public int getGroupsMask() {
62         return nlGroupsMask;
63     }
64 
toString()65     @Override public String toString() {
66       return Objects.toString(this);
67     }
68 }
69