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
.pcap
.core
.protocol
.tcp
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.linuxtools
.pcap
.core
.endpoint
.ProtocolEndpoint
;
20 * Class that extends the {@link ProtocolEndpoint} class. It represents the
21 * endpoint at a TCP level.
23 * @author Vincent Perot
25 public class TCPEndpoint
extends ProtocolEndpoint
{
27 private final int fPort
;
30 * Constructor of the {@link TCPEndpoint} class. It takes a packet to get
31 * its endpoint. Since every packet has two endpoints (source and
32 * destination), the isSourceEndpoint parameter is used to specify which
36 * The packet that contains the endpoints.
37 * @param isSourceEndpoint
38 * Whether to take the source or the destination endpoint of the
41 public TCPEndpoint(TCPPacket packet
, boolean isSourceEndpoint
) {
42 super(packet
, isSourceEndpoint
);
43 fPort
= isSourceEndpoint ? packet
.getSourcePort() : packet
.getDestinationPort();
47 public int hashCode() {
50 ProtocolEndpoint endpoint
= getParentEndpoint();
51 if (endpoint
== null) {
54 result
= endpoint
.hashCode();
56 result
= prime
* result
+ fPort
;
61 public boolean equals(@Nullable Object obj
) {
65 if (!(obj
instanceof TCPEndpoint
)) {
69 TCPEndpoint other
= (TCPEndpoint
) obj
;
72 boolean localEquals
= (fPort
== other
.fPort
);
77 // Check above layers.
78 ProtocolEndpoint endpoint
= getParentEndpoint();
79 if (endpoint
!= null) {
80 return endpoint
.equals(other
.getParentEndpoint());
86 public String
toString() {
87 ProtocolEndpoint endpoint
= getParentEndpoint();
88 if (endpoint
== null) {
89 @SuppressWarnings("null")
91 String ret
= String
.valueOf(fPort
);
94 return endpoint
.toString() + '/' + fPort
;