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.net;
006
007/**
008 * Forward ports to another host. This is primarily useful for accessing Ethernet-connected devices
009 * from a computer tethered to the RoboRIO USB port.
010 */
011public final class PortForwarder {
012  private PortForwarder() {
013    throw new UnsupportedOperationException("This is a utility class!");
014  }
015
016  /**
017   * Forward a local TCP port to a remote host and port. Note that local ports less than 1024 won't
018   * work as a normal user.
019   *
020   * @param port local port number
021   * @param remoteHost remote IP address / DNS name
022   * @param remotePort remote port number
023   */
024  public static void add(int port, String remoteHost, int remotePort) {
025    WPINetJNI.addPortForwarder(port, remoteHost, remotePort);
026  }
027
028  /**
029   * Stop TCP forwarding on a port.
030   *
031   * @param port local port number
032   */
033  public static void remove(int port) {
034    WPINetJNI.removePortForwarder(port);
035  }
036}