Commit | Line | Data |
---|---|---|
5255c030 VP |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Vincent Perot - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
93d1d135 | 13 | package org.eclipse.linuxtools.internal.pcap.core.util; |
5255c030 | 14 | |
93d1d135 | 15 | import org.eclipse.linuxtools.internal.pcap.core.protocol.Protocol; |
5255c030 VP |
16 | |
17 | // TODO finish this | |
18 | // TODO maybe match it to protocol instead of string. | |
19 | ||
20 | /** | |
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. | |
24 | * | |
25 | * See http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers | |
26 | * | |
27 | * @author Vincent Perot | |
28 | */ | |
29 | public final class IPProtocolNumberHelper { | |
30 | ||
31 | /** Protocol Number ICMP */ | |
32 | public static final int PROTOCOL_NUMBER_ICMP = 1; | |
33 | ||
34 | /** Protocol Number IGMP */ | |
35 | public static final int PROTOCOL_NUMBER_IGMP = 2; | |
36 | ||
37 | /** Protocol Number TCP */ | |
38 | public static final int PROTOCOL_NUMBER_TCP = 6; | |
39 | ||
40 | /** Protocol Number UDP */ | |
41 | public static final int PROTOCOL_NUMBER_UDP = 17; | |
42 | ||
43 | /** Protocol Number Encapsulated IPv6 */ | |
44 | public static final int PROTOCOL_NUMBER_ENCAP_IPV6 = 41; | |
45 | ||
46 | /** Protocol Number OSPF */ | |
47 | public static final int PROTOCOL_NUMBER_OSPF = 89; | |
48 | ||
49 | /** Protocol Number SCTP */ | |
50 | public static final int PROTOCOL_NUMBER_SCTP = 132; | |
51 | ||
52 | private IPProtocolNumberHelper() {} | |
53 | ||
54 | /** | |
55 | * Method that match the protocol number to a protocol as a string. | |
56 | * | |
57 | * @param protocolNumber | |
58 | * The protocol number as an int. | |
59 | * @return The protocol as a string. | |
60 | */ | |
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 Protocol.TCP.getName(); | |
69 | case PROTOCOL_NUMBER_UDP: | |
70 | return Protocol.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$ | |
77 | default: | |
78 | return "Unknown"; //$NON-NLS-1$ | |
79 | } | |
80 | } | |
81 | } |