diff --git a/net_freebsd.go b/net_freebsd.go index df0038c..72e1266 100644 --- a/net_freebsd.go +++ b/net_freebsd.go @@ -14,7 +14,19 @@ import ( "strconv" ) -func setupPortForward(ip, port string) { +func setupPortForward(ruleName, ip, port string) { + pfrule := "\"rdr pass on $ext_if proto { tcp, udp } from any to any port {" + port + "} -> " + ip + "\"" + + in, err := exec.Command("pfctl", "-a", "\""+ruleName+"\"", "-f", "-").StdinPipe() + defer in.Close() + if err != nil { + log.Println("Port Forwarding:", err) + } + + _, err = in.Write([]byte(pfrule)) + if err != nil { + log.Println("Port Forwarding:", err) + } } func portUsageCount(ports ...int) int { diff --git a/net_linux.go b/net_linux.go index eed00cf..e1f3efa 100644 --- a/net_linux.go +++ b/net_linux.go @@ -15,7 +15,7 @@ import ( ) // just have this stub to allow building on Linux -func setupPortForward(ip, port string) { +func setupPortForward(ruleName, ip, port string) { log.Print("Port forwarding not currently implemented for Linux/iptables") }