2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.amazondashbutton.internal.pcap;
15 import java.util.Collections;
17 import java.util.stream.Collectors;
19 import org.pcap4j.core.PcapNativeException;
20 import org.pcap4j.core.Pcaps;
24 * A simple utitlity class which encapsulates {@link Pcaps} and which catches checked exceptions and transforms them
25 * into {@link RuntimeException}s.
27 * @author Oliver Libutzki - Initial contribution
30 public class PcapUtil {
33 * Returns all Pcap network interfaces relying on {@link Pcaps#findAllDevs()}.
35 * @return A {@link Set} of all {@link PcapNetworkInterfaceWrapper}s
37 public static Set<PcapNetworkInterfaceWrapper> getAllNetworkInterfaces() {
39 return Collections.unmodifiableSet(Pcaps.findAllDevs().stream().map(PcapNetworkInterfaceWrapper.TRANSFORMER)
40 .collect(Collectors.toSet()));
41 } catch (PcapNativeException e) {
42 throw new RuntimeException(e);
47 * Returns the Pcap network interface with the given name relying on {@link Pcaps#getDevByName(String)}. If no
48 * interface is found, null is returned.
50 * @param name The name of the Pcap network interface
51 * @return The network interface with the given name. Returns null, if no interface is found
53 public static PcapNetworkInterfaceWrapper getNetworkInterfaceByName(String name) {
55 return PcapNetworkInterfaceWrapper.TRANSFORMER.apply(Pcaps.getDevByName(name));
56 } catch (PcapNativeException e) {
57 throw new RuntimeException(e);