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 dalvik.annotation.compat.UnsupportedAppUsage;
20 import libcore.util.Objects;
21 import java.net.SocketAddress;
22 
23 /**
24  * Packet socket address.
25  *
26  * Corresponds to Linux's {@code struct sockaddr_ll}.
27  *
28  * @hide
29  */
30 @libcore.api.CorePlatformApi
31 public final class PacketSocketAddress extends SocketAddress {
32     /** Protocol. An Ethernet protocol type, e.g., {@code ETH_P_IPV6}. */
33     public short sll_protocol;
34 
35     /** Interface index. */
36     public int sll_ifindex;
37 
38     /** ARP hardware type. One of the {@code ARPHRD_*} constants. */
39     public short sll_hatype;
40 
41     /** Packet type. One of the {@code PACKET_*} constants, such as {@code PACKET_OTHERHOST}. */
42     public byte sll_pkttype;
43 
44     /** Hardware address. */
45     public byte[] sll_addr;
46 
47     /** Constructs a new PacketSocketAddress. */
PacketSocketAddress(short sll_protocol, int sll_ifindex, short sll_hatype, byte sll_pkttype, byte[] sll_addr)48     public PacketSocketAddress(short sll_protocol, int sll_ifindex,
49             short sll_hatype, byte sll_pkttype, byte[] sll_addr) {
50         this.sll_protocol = sll_protocol;
51         this.sll_ifindex = sll_ifindex;
52         this.sll_hatype = sll_hatype;
53         this.sll_pkttype = sll_pkttype;
54         this.sll_addr = sll_addr;
55     }
56 
57     /** Constructs a new PacketSocketAddress suitable for binding to. */
58     @UnsupportedAppUsage
59     @libcore.api.CorePlatformApi
PacketSocketAddress(short sll_protocol, int sll_ifindex)60     public PacketSocketAddress(short sll_protocol, int sll_ifindex) {
61         this(sll_protocol, sll_ifindex, (short) 0, (byte) 0, null);
62     }
63 
64     /** Constructs a new PacketSocketAddress suitable for sending to. */
65     @UnsupportedAppUsage
66     @libcore.api.CorePlatformApi
PacketSocketAddress(int sll_ifindex, byte[] sll_addr)67     public PacketSocketAddress(int sll_ifindex, byte[] sll_addr) {
68         this((short) 0, sll_ifindex, (short) 0, (byte) 0, sll_addr);
69     }
70 }
71