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 * Packet socket address. 26 * 27 * Corresponds to Linux's {@code struct sockaddr_ll}. 28 * 29 * @hide 30 */ 31 @libcore.api.CorePlatformApi 32 public final class PacketSocketAddress extends SocketAddress { 33 /** Protocol. An Ethernet protocol type, e.g., {@link OsConstants#ETH_P_IPV6}. */ 34 public final int sll_protocol; 35 36 /** Interface index. */ 37 public final int sll_ifindex; 38 39 /** 40 * ARP hardware type. One of the {@code ARPHRD_*} constants, such as 41 * {@link OsConstants#ARPHRD_ETHER}. 42 */ 43 public final int sll_hatype; 44 45 /** 46 * Packet type. 47 */ 48 public final int sll_pkttype; 49 50 /** Hardware address. */ 51 public final byte[] sll_addr; 52 53 /** Constructs a new PacketSocketAddress. Used from native code. */ PacketSocketAddress(int sll_protocol, int sll_ifindex, int sll_hatype, int sll_pkttype, byte[] sll_addr)54 public PacketSocketAddress(int sll_protocol, int sll_ifindex, int sll_hatype, int sll_pkttype, 55 byte[] sll_addr) { 56 this.sll_protocol = sll_protocol; 57 this.sll_ifindex = sll_ifindex; 58 this.sll_hatype = sll_hatype; 59 this.sll_pkttype = sll_pkttype; 60 this.sll_addr = sll_addr; 61 } 62 63 /** Constructs a new PacketSocketAddress with all the "in" parameters. */ 64 @libcore.api.CorePlatformApi PacketSocketAddress(int sll_protocol, int sll_ifindex, byte[] sll_addr)65 public PacketSocketAddress(int sll_protocol, int sll_ifindex, byte[] sll_addr) { 66 this.sll_protocol = sll_protocol; 67 this.sll_ifindex = sll_ifindex; 68 this.sll_hatype = 0; 69 this.sll_pkttype = 0; 70 this.sll_addr = sll_addr; 71 } 72 73 /** Legacy constructor. Kept for @UnsupportedAppUsage only. */ 74 @UnsupportedAppUsage PacketSocketAddress(short sll_protocol, int sll_ifindex)75 public PacketSocketAddress(short sll_protocol, int sll_ifindex) { 76 this.sll_protocol = sll_protocol; 77 this.sll_ifindex = sll_ifindex; 78 this.sll_hatype = 0; 79 this.sll_pkttype = 0; 80 this.sll_addr = null; 81 } 82 83 /** Legacy constructor. Kept for @UnsupportedAppUsage only. */ 84 @UnsupportedAppUsage PacketSocketAddress(int sll_ifindex, byte[] sll_addr)85 public PacketSocketAddress(int sll_ifindex, byte[] sll_addr) { 86 this.sll_protocol = 0; 87 this.sll_ifindex = sll_ifindex; 88 this.sll_hatype = 0; 89 this.sll_pkttype = 0; 90 this.sll_addr = sll_addr; 91 } 92 93 @Override toString()94 public String toString() { 95 return Objects.toString(this); 96 } 97 } 98