38 lines
776 B
Go
38 lines
776 B
Go
package sshtun
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strconv"
|
|
|
|
"github.com/Neur0toxine/sshpoke/pkg/errtools"
|
|
)
|
|
|
|
type Forward struct {
|
|
// local service to be forwarded
|
|
Local Endpoint `json:"local"`
|
|
// remote forwarding port (on remote SSH server network)
|
|
Remote Endpoint `json:"remote"`
|
|
}
|
|
|
|
func AddrToEndpoint(address string) Endpoint {
|
|
host, port, err := net.SplitHostPort(address)
|
|
if err != nil && errtools.IsPortMissingErr(err) {
|
|
return Endpoint{Host: address, Port: 22}
|
|
}
|
|
portNum, err := strconv.Atoi(port)
|
|
if err != nil {
|
|
portNum = 22
|
|
}
|
|
return Endpoint{Host: host, Port: portNum}
|
|
}
|
|
|
|
type Endpoint struct {
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
}
|
|
|
|
func (endpoint *Endpoint) String() string {
|
|
return fmt.Sprintf("%s:%d", endpoint.Host, endpoint.Port)
|
|
}
|