1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.pcap
.core
.protocol
.ipv4
;
15 import java
.net
.Inet4Address
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.endpoint
.ProtocolEndpoint
;
22 * Class that extends the {@link ProtocolEndpoint} class. It represents the
23 * endpoint at an IPv4 level.
25 * @author Vincent Perot
27 public class IPv4Endpoint
extends ProtocolEndpoint
{
29 private final Inet4Address fIPAddress
;
32 * Constructor of the {@link IPv4Endpoint} class. It takes a packet to get
33 * its endpoint. Since every packet has two endpoints (source and
34 * destination), the isSourceEndpoint parameter is used to specify which
38 * The packet that contains the endpoints.
39 * @param isSourceEndpoint
40 * Whether to take the source or the destination endpoint of the
43 public IPv4Endpoint(IPv4Packet packet
, boolean isSourceEndpoint
) {
44 super(packet
, isSourceEndpoint
);
45 fIPAddress
= isSourceEndpoint ? packet
.getSourceIpAddress() : packet
.getDestinationIpAddress();
49 public int hashCode() {
53 ProtocolEndpoint endpoint
= getParentEndpoint();
54 if (endpoint
== null) {
57 result
= endpoint
.hashCode();
60 result
= prime
* result
+ fIPAddress
.hashCode();
65 public boolean equals(@Nullable Object obj
) {
69 if (!(obj
instanceof IPv4Endpoint
)) {
73 IPv4Endpoint other
= (IPv4Endpoint
) obj
;
76 boolean localEquals
= fIPAddress
.equals(other
.fIPAddress
);
81 // Check above layers.
82 ProtocolEndpoint endpoint
= getParentEndpoint();
83 if (endpoint
!= null) {
84 return endpoint
.equals(other
.getParentEndpoint());
90 public String
toString() {
91 ProtocolEndpoint endpoint
= getParentEndpoint();
92 if (endpoint
== null) {
93 @SuppressWarnings("null")
94 @NonNull String ret
= fIPAddress
.getHostAddress();
97 return endpoint
.toString() + '/' + fIPAddress
.getHostAddress();