1 /* 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 17 package android.system; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 23 import java.net.SocketAddress; 24 import libcore.api.CorePlatformApi; 25 import libcore.util.Objects; 26 27 /** 28 * A virtio-vsock address {@link VmSocketAddress}. 29 * 30 * <p> 31 * virtio-vsock socket address, linux specific. 32 * 33 * <p> 34 * {@link VmSocketAddress} corresponds to {@code struct sockaddr_vm} in 35 * bionic/libc/kernel/uapi/linux/vm_sockets.h. 36 * 37 * <p> 38 * Currently virtio-vsock is used as a generic purpose pipe in emulators 39 * to talk to the host. 40 * 41 * @see <a href="https://man7.org/linux/man-pages/man7/vsock.7.html">vsock(7)</a> 42 * @hide 43 */ 44 @SystemApi(client = MODULE_LIBRARIES) 45 @libcore.api.CorePlatformApi(status = CorePlatformApi.Status.STABLE) 46 public final class VmSocketAddress extends SocketAddress { 47 /** 48 * sockaddr_vm::svmPort, see {@code struct sockaddr_vm} in 49 * bionic/libc/kernel/uapi/linux/vm_sockets.h for more details. 50 */ 51 private int svmPort; 52 53 /** 54 * sockaddr_vm::svmCid, see {@code struct sockaddr_vm} in 55 * bionic/libc/kernel/uapi/linux/vm_sockets.h for more details. 56 */ 57 private int svmCid; 58 59 /** 60 * Creates a new instance of VmSocketAddress. 61 * 62 * @param svmPort The svmPort field value, 63 * see {@link OsConstants.VMADDR_PORT_ANY}. 64 * @param svmCid The svmCid field value, 65 * see OsConstants.VMADDR_CID_* for VMADDR_CID_* values. 66 * 67 * @hide 68 */ 69 @SystemApi(client = MODULE_LIBRARIES) 70 @CorePlatformApi(status = CorePlatformApi.Status.STABLE) VmSocketAddress(int svmPort, int svmCid)71 public VmSocketAddress(int svmPort, int svmCid) { 72 this.svmPort = svmPort; 73 this.svmCid = svmCid; 74 } 75 76 /** 77 * Returns the value of the svmPort field 78 * 79 * @hide 80 */ 81 @SystemApi(client = MODULE_LIBRARIES) 82 @libcore.api.CorePlatformApi(status = CorePlatformApi.Status.STABLE) getSvmPort()83 public int getSvmPort() { 84 return svmPort; 85 } 86 87 /** 88 * Returns the value of the svmCid field 89 * 90 * @hide 91 */ 92 @SystemApi(client = MODULE_LIBRARIES) 93 @libcore.api.CorePlatformApi(status = CorePlatformApi.Status.STABLE) getSvmCid()94 public int getSvmCid() { 95 return svmCid; 96 } 97 } 98