Skip to content

Instantly share code, notes, and snippets.

@Leechael
Created September 8, 2012 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leechael/3677837 to your computer and use it in GitHub Desktop.
Save Leechael/3677837 to your computer and use it in GitHub Desktop.
Added `:both` support for forward_port protocol configuration
--- virtualbox_4_1.rb.orig 2012-09-09 01:24:56.000000000 +0800
+++ virtualbox_4_1.rb 2012-09-09 01:39:32.000000000 +0800
@@ -135,15 +135,22 @@
def forward_ports(ports)
args = []
ports.each do |options|
- pf_builder = [options[:name],
- options[:protocol] || "tcp",
- "",
- options[:hostport],
- "",
- options[:guestport]]
+ protocols = {
+ :both => ["tcp", "udp"],
+ :tcp => ["tcp"],
+ :udp => ["udp"]
+ }
+ protocols[options[:protocol] || :tcp].each do |protocol|
+ pf_builder = [protocol + options[:name],
+ protocol,
+ "",
+ options[:hostport],
+ "",
+ options[:guestport]]
- args.concat(["--natpf#{options[:adapter] || 1}",
- pf_builder.join(",")])
+ args.concat(["--natpf#{options[:adapter] || 1}",
+ pf_builder.join(",")])
+ end
end
execute("modifyvm", @uuid, *args) if !args.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment