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 VP |
14 | |
15 | // TODO finish this | |
16 | // TODO maybe match it to protocol instead of string. | |
17 | ||
18 | /** | |
19 | * Helper that is used to help mapping a certain ethertype to a particular | |
20 | * protocol (i.e. IPv4). This is used when finding the child packet of an | |
21 | * Ethernet packet, for instance. | |
22 | * | |
23 | * See http://en.wikipedia.org/wiki/EtherType | |
24 | * | |
25 | * @author Vincent Perot | |
26 | */ | |
27 | public final class EthertypeHelper { | |
28 | ||
29 | /** EtherType IPv4 */ | |
30 | public static final int ETHERTYPE_IPV4 = 0x0800; | |
31 | ||
32 | /** EtherType ARP */ | |
33 | public static final int ETHERTYPE_ARP = 0x0806; | |
34 | ||
35 | /** EtherType Wake-On-LAN */ | |
36 | public static final int ETHERTYPE_WAKE_ON_LAN = 0x0842; | |
37 | ||
38 | /** EtherType TRILL */ | |
39 | public static final int ETHERTYPE_TRILL = 0x22F3; | |
40 | ||
41 | /** EtherType DECnet Phase IV */ | |
42 | public static final int ETHERTYPE_DECNET_PHASE_IV = 0x6003; | |
43 | ||
44 | private EthertypeHelper() {} | |
45 | ||
46 | /** | |
47 | * Method that matches the ethertype as a number, to a protocol as a string. | |
48 | * | |
49 | * @param ethertype | |
50 | * The Ethertype as an int. | |
51 | * @return The protocol as a string. | |
52 | */ | |
53 | public static String toString(int ethertype) { | |
54 | switch (ethertype) { | |
55 | case ETHERTYPE_IPV4: | |
56 | return "Internet Protocol Version 4"; //$NON-NLS-1$ | |
57 | case ETHERTYPE_ARP: | |
58 | return "Address Resolution Protocol"; //$NON-NLS-1$ | |
59 | case ETHERTYPE_WAKE_ON_LAN: | |
60 | return "Wake-on-LAN"; //$NON-NLS-1$ | |
61 | case ETHERTYPE_TRILL: | |
62 | return "IETF TRILL Protocol"; //$NON-NLS-1$ | |
63 | case ETHERTYPE_DECNET_PHASE_IV: | |
64 | return "DECnet Phase IV"; //$NON-NLS-1$ | |
65 | default: | |
66 | return "Unknown"; //$NON-NLS-1$ | |
67 | } | |
68 | } | |
69 | ||
70 | /** | |
71 | * Convert an ethertype (int) into its string representation. This allows | |
72 | * the mapping of ethertype to the real protocol name. | |
73 | * | |
74 | * @param type | |
75 | * The Ethertype to convert. | |
76 | * @return The Ethertype as a string. | |
77 | */ | |
78 | public static String toEtherType(int type) { | |
79 | return toString(type) + " (0x" + String.format("%04x", type) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
80 | } | |
81 | ||
82 | } |