Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Commit 8ce5081

Browse files
Sven DowideitSven Dowideit
authored andcommitted
check to see if the hostonlyif created the dhcp server and if it did, modify
OSX and Windows do not seem to work the same way :(
1 parent c033ddb commit 8ce5081

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

virtualbox/dhcp.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ type DHCP struct {
1616
}
1717

1818
func addDHCP(kind, name string, d DHCP) error {
19-
args := []string{"dhcpserver", "add",
19+
command := "modify"
20+
21+
// On some platforms (OSX), creating a hostonlyinterface adds a default dhcpserver
22+
// While on others (Windows?) it does not.
23+
dhcps, err := DHCPs()
24+
if err != nil {
25+
return err
26+
}
27+
28+
if _, ok := dhcps[name]; !ok {
29+
command = "add"
30+
}
31+
32+
args := []string{"dhcpserver", command,
2033
kind, name,
2134
"--ip", d.IPv4.IP.String(),
2235
"--netmask", net.IP(d.IPv4.Mask).String(),
@@ -38,7 +51,7 @@ func AddInternalDHCP(netname string, d DHCP) error {
3851

3952
// AddHostonlyDHCP adds a DHCP server to a host-only network.
4053
func AddHostonlyDHCP(ifname string, d DHCP) error {
41-
return addDHCP("--ifname", ifname, d)
54+
return addDHCP("--netname", "HostInterfaceNetworking-"+ifname, d)
4255
}
4356

4457
// DHCPs gets all DHCP server settings in a map keyed by DHCP.NetworkName.

0 commit comments

Comments
 (0)