drivers/virtualbox/virtualbox.go
func setPortForwarding(d *Driver, interfaceNum int, mapName, protocol string, guestPort, desiredHostPort int) (int, error) {
	actualHostPort, err := getAvailableTCPPort(desiredHostPort)
	if err != nil {
		return -1, err
	}
	if desiredHostPort != actualHostPort && desiredHostPort != 0 {
		log.Debugf("NAT forwarding host port for guest port %d (%s) changed from %d to %d",
			guestPort, mapName, desiredHostPort, actualHostPort)
	}
	cmd := fmt.Sprintf("--natpf%d", interfaceNum)
	d.vbm("modifyvm", d.MachineName, cmd, "delete", mapName)
	if err := d.vbm("modifyvm", d.MachineName,
		cmd, fmt.Sprintf("%s,%s,127.0.0.1,%d,,%d", mapName, protocol, actualHostPort, guestPort)); err != nil {
		return -1, err
	}
	return actualHostPort, nil
}
func setPortForwarding(d *Driver, interfaceNum int, mapName, protocol string, guestPort, desiredHostPort int) (int, error) {
	actualHostPort, err := getAvailableTCPPort(desiredHostPort)
	if err != nil {
		return -1, err
	}
	if desiredHostPort != actualHostPort && desiredHostPort != 0 {
		log.Debugf("NAT forwarding host port for guest port %d (%s) changed from %d to %d",
			guestPort, mapName, desiredHostPort, actualHostPort)
	}
	cmd := fmt.Sprintf("--natpf%d", interfaceNum)
	d.vbm("modifyvm", d.MachineName, cmd, "delete", mapName)
	if err := d.vbm("modifyvm", d.MachineName,
		cmd, fmt.Sprintf("%s,%s,127.0.0.1,%d,,%d", mapName, protocol, actualHostPort, guestPort)); err != nil {
		return -1, err
	}
	return actualHostPort, nil
}
func setPortForwarding ( d * Driver , interfaceNum int , mapName , protocol string , guestPort , desiredHostPort int ) ( int , error ) { actualHostPort , err := getAvailableTCPPort ( desiredHostPort ) if err != nil { return - 1 , err } if desiredHostPort != actualHostPort && desiredHostPort != 0 { log . Debugf ( " " , guestPort , mapName , desiredHostPort , actualHostPort ) } cmd := fmt . Sprintf ( " " , interfaceNum ) d . vbm ( " " , d . MachineName , cmd , " " , mapName ) if err := d . vbm ( " " , d . MachineName , cmd , fmt . Sprintf ( " " , mapName , protocol , actualHostPort , guestPort ) ) ; err != nil { return - 1 , err } return actualHostPort , nil }
// Setup a NAT port forwarding entry.
Setup a NAT port forwarding entry .