Browse Source

Add support for setting IPv6 address on macOS

Tom Mychost 1 year ago
parent
commit
228ee7ca89
1 changed files with 7 additions and 1 deletions
  1. 7 1
      pkg/vpn/interface_darwin.go

+ 7 - 1
pkg/vpn/interface_darwin.go

@@ -54,7 +54,13 @@ func prepareInterface(c *Config) error {
 
 	// Add the address to the interface. This is not directly possible with the `net` package,
 	// so we use the `ifconfig` command.
-	cmd = exec.Command("ifconfig", iface.Name, "inet", ip.String(), ip.String())
+	if ip.To4() == nil {
+		// IPV6
+		cmd = exec.Command("ifconfig", iface.Name, "inet6", ip.String())
+	} else {
+		// IPv4
+		cmd = exec.Command("ifconfig", iface.Name, "inet", ip.String(), ip.String())
+	}
 	err = cmd.Run()
 	if err != nil {
 		return err