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
;
16 // TODO maybe match it to protocol instead of string.
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.
23 * See http://en.wikipedia.org/wiki/EtherType
25 * @author Vincent Perot
27 public final class EthertypeHelper
{
30 public static final int ETHERTYPE_IPV4
= 0x0800;
33 public static final int ETHERTYPE_ARP
= 0x0806;
35 /** EtherType Wake-On-LAN */
36 public static final int ETHERTYPE_WAKE_ON_LAN
= 0x0842;
38 /** EtherType TRILL */
39 public static final int ETHERTYPE_TRILL
= 0x22F3;
41 /** EtherType DECnet Phase IV */
42 public static final int ETHERTYPE_DECNET_PHASE_IV
= 0x6003;
44 private EthertypeHelper() {}
47 * Method that matches the ethertype as a number, to a protocol as a string.
50 * The Ethertype as an int.
51 * @return The protocol as a string.
53 public static String
toString(int ethertype
) {
56 return "Internet Protocol Version 4"; //$NON-NLS-1$
58 return "Address Resolution Protocol"; //$NON-NLS-1$
59 case ETHERTYPE_WAKE_ON_LAN
:
60 return "Wake-on-LAN"; //$NON-NLS-1$
62 return "IETF TRILL Protocol"; //$NON-NLS-1$
63 case ETHERTYPE_DECNET_PHASE_IV
:
64 return "DECnet Phase IV"; //$NON-NLS-1$
66 return "Unknown"; //$NON-NLS-1$
71 * Convert an ethertype (int) into its string representation. This allows
72 * the mapping of ethertype to the real protocol name.
75 * The Ethertype to convert.
76 * @return The Ethertype as a string.
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$