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 java.net.SocketAddress; 20 21 /** 22 * A virtio-vsock address {@link VmSocketAddress}. 23 * 24 * <p> 25 * virtio-vsock socket address, linux specific. 26 * 27 * <p> 28 * {@link VmSocketAddress} corresponds to {@code struct sockaddr_vm} in 29 * bionic/libc/kernel/uapi/linux/vm_sockets.h. 30 * 31 * <p> 32 * Currently virtio-vsock is used as a generic purpose pipe in emulators 33 * to talk to the host. Most I/O operations using this address via {@link Os} class will require 34 * additional permissions to talk to the host. 35 * 36 * @see <a href="https://man7.org/linux/man-pages/man7/vsock.7.html">vsock(7)</a> 37 */ 38 public final class VmSocketAddress extends SocketAddress { 39 /** 40 * sockaddr_vm::svmPort, see {@code struct sockaddr_vm} in 41 * bionic/libc/kernel/uapi/linux/vm_sockets.h for more details. 42 */ 43 private int svmPort; 44 45 /** 46 * sockaddr_vm::svmCid, see {@code struct sockaddr_vm} in 47 * bionic/libc/kernel/uapi/linux/vm_sockets.h for more details. 48 */ 49 private int svmCid; 50 51 /** 52 * Creates a new instance of VmSocketAddress. 53 * 54 * @param svmPort The svmPort field value, 55 * see {@link OsConstants#VMADDR_PORT_ANY}. 56 * @param svmCid The svmCid field value, 57 * see OsConstants.VMADDR_CID_* for VMADDR_CID_* values. 58 */ VmSocketAddress(int svmPort, int svmCid)59 public VmSocketAddress(int svmPort, int svmCid) { 60 this.svmPort = svmPort; 61 this.svmCid = svmCid; 62 } 63 64 /** 65 * Returns the value of the svmPort field 66 */ getSvmPort()67 public int getSvmPort() { 68 return svmPort; 69 } 70 71 /** 72 * Returns the value of the svmCid field 73 */ getSvmCid()74 public int getSvmCid() { 75 return svmCid; 76 } 77 } 78