001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.util.net;
006
007import edu.wpi.first.util.WPIUtilJNI;
008
009/**
010 * Forward ports to another host. This is primarily useful for accessing Ethernet-connected devices
011 * from a computer tethered to the RoboRIO USB port.
012 */
013public final class PortForwarder {
014  private PortForwarder() {
015    throw new UnsupportedOperationException("This is a utility class!");
016  }
017
018  /**
019   * Forward a local TCP port to a remote host and port. Note that local ports less than 1024 won't
020   * work as a normal user.
021   *
022   * @param port local port number
023   * @param remoteHost remote IP address / DNS name
024   * @param remotePort remote port number
025   */
026  public static void add(int port, String remoteHost, int remotePort) {
027    WPIUtilJNI.addPortForwarder(port, remoteHost, remotePort);
028  }
029
030  /**
031   * Stop TCP forwarding on a port.
032   *
033   * @param port local port number
034   */
035  public static void remove(int port) {
036    WPIUtilJNI.removePortForwarder(port);
037  }
038}