sshpoke/internal/server/driver/ssh/sshtun/forward.go

38 lines
776 B
Go
Raw Normal View History

2023-11-18 21:23:29 +03:00
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}
2023-11-18 21:23:29 +03:00
}
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)
}