View Javadoc
1   /*
2    * Copyright 2023 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.channel.epoll;
18  
19  import java.net.SocketAddress;
20  
21  /**
22   * A address for a
23   * <a href="https://man7.org/linux/man-pages/man7/vsock.7.html">VM sockets (Linux VSOCK address family)</a>.
24   */
25  
26  public final class VSockAddress extends SocketAddress {
27      private static final long serialVersionUID = 8600894096347158429L;
28  
29      public static final int VMADDR_CID_ANY = -1;
30      public static final int VMADDR_CID_HYPERVISOR = 0;
31      public static final int VMADDR_CID_LOCAL = 1;
32      public static final int VMADDR_CID_HOST = 2;
33  
34      public static final int VMADDR_PORT_ANY = -1;
35  
36      private final int cid;
37      private final int port;
38  
39      public VSockAddress(int cid, int port) {
40          this.cid = cid;
41          this.port = port;
42      }
43  
44      public int getCid() {
45          return cid;
46      }
47  
48      public int getPort() {
49          return port;
50      }
51  
52      @Override
53      public String toString() {
54          return "VSockAddress{" +
55                  "cid=" + cid +
56                  ", port=" + port +
57                  '}';
58      }
59  
60      @Override
61      public boolean equals(Object o) {
62          if (this == o) {
63              return true;
64          }
65          if (!(o instanceof VSockAddress)) {
66              return false;
67          }
68  
69          VSockAddress that = (VSockAddress) o;
70  
71          return cid == that.cid && port == that.port;
72      }
73  
74      @Override
75      public int hashCode() {
76          int result = cid;
77          result = 31 * result + port;
78          return result;
79      }
80  }