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