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
.util
;
15 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.protocol
.PcapProtocol
;
18 // TODO maybe match it to protocol instead of string.
21 * Helper that is used to help mapping a certain protocol number to a particular
22 * protocol (i.e. TCP). This is used when finding the child packet of an IPv4
23 * packet, for instance.
25 * See http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
27 * @author Vincent Perot
29 public final class IPProtocolNumberHelper
{
31 /** Protocol Number ICMP */
32 public static final int PROTOCOL_NUMBER_ICMP
= 1;
34 /** Protocol Number IGMP */
35 public static final int PROTOCOL_NUMBER_IGMP
= 2;
37 /** Protocol Number TCP */
38 public static final int PROTOCOL_NUMBER_TCP
= 6;
40 /** Protocol Number UDP */
41 public static final int PROTOCOL_NUMBER_UDP
= 17;
43 /** Protocol Number Encapsulated IPv6 */
44 public static final int PROTOCOL_NUMBER_ENCAP_IPV6
= 41;
46 /** Protocol Number OSPF */
47 public static final int PROTOCOL_NUMBER_OSPF
= 89;
49 /** Protocol Number SCTP */
50 public static final int PROTOCOL_NUMBER_SCTP
= 132;
52 private IPProtocolNumberHelper() {}
55 * Method that match the protocol number to a protocol as a string.
57 * @param protocolNumber
58 * The protocol number as an int.
59 * @return The protocol as a string.
61 public static String
toString(int protocolNumber
) {
62 switch (protocolNumber
) {
63 case PROTOCOL_NUMBER_ICMP
:
64 return "ICMP"; //$NON-NLS-1$
65 case PROTOCOL_NUMBER_IGMP
:
66 return "IGMP"; //$NON-NLS-1$
67 case PROTOCOL_NUMBER_TCP
:
68 return PcapProtocol
.TCP
.getName();
69 case PROTOCOL_NUMBER_UDP
:
70 return PcapProtocol
.UDP
.getName();
71 case PROTOCOL_NUMBER_ENCAP_IPV6
:
72 return "IPv6"; //$NON-NLS-1$
73 case PROTOCOL_NUMBER_OSPF
:
74 return "OSPF"; //$NON-NLS-1$
75 case PROTOCOL_NUMBER_SCTP
:
76 return "SCTP"; //$NON-NLS-1$
78 return "Unknown"; //$NON-NLS-1$