View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2024 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix;
19  
20  import java.io.IOException;
21  
22  /**
23   * VSOCK-specific code that resides in the native library. To be used by {@code AFVSOCKSocket} and
24   * {@code AFVSOCKDatagramSocket} only.
25   *
26   * @author Christian Kohlschütter
27   */
28  public final class AFVSOCKSocketImplExtensions implements
29      AFSocketImplExtensions<AFVSOCKSocketAddress> {
30    @SuppressWarnings("unused")
31    private final AncillaryDataSupport ancillaryDataSupport; // NOPMD
32  
33    AFVSOCKSocketImplExtensions(AncillaryDataSupport ancillaryDataSupport) {
34      this.ancillaryDataSupport = ancillaryDataSupport;
35    }
36  
37    /**
38     * Returns the local CID.
39     *
40     * If the system does not support vsock, or status about support cannot be retrieved, -1
41     * ({@link AFVSOCKSocketAddress#VMADDR_CID_ANY}) is returned.
42     *
43     * The value may be cached upon initialization of the library.
44     *
45     * @return The CID, or -1.
46     * @throws IOException on error.
47     */
48    public int getLocalCID() throws IOException {
49      return NativeUnixSocket.vsockGetLocalCID();
50    }
51  }