Skip to content

Commit

Permalink
chore: use file operation instead of cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
cxz66666 committed Nov 11, 2023
1 parent 0dbae1b commit 5a3edf2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions stack/tun/stack_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"golang.org/x/sys/unix"
"net"
"net/netip"
"os"
"os/exec"
"sync"
"syscall"
Expand Down Expand Up @@ -53,11 +54,15 @@ func (s *Stack) AddRoute(target string) error {
}

func (s *Stack) AddDnsServer(dnsServer string, targetHost string) error {
command := exec.Command("echo", "nameserver", dnsServer, ">", fmt.Sprintf("/etc/resolver/%s", targetHost))
err := command.Run()
fileName := fmt.Sprintf("/etc/resolver/%s", targetHost)
file, err := os.Create(fileName)
if err != nil {
return err
}
defer file.Close()

file.WriteString(fmt.Sprintf("nameserver %s\n", dnsServer))

terminal_func.RegisterTerminalFunc("DelDnsServer_"+targetHost, func(ctx context.Context) error {
delCommand := exec.Command("rm", fmt.Sprintf("/etc/resolver/%s", targetHost))
delErr := delCommand.Run()
Expand Down

0 comments on commit 5a3edf2

Please sign in to comment.