Skip to content

Commit

Permalink
surround interface name with double quote in case of name have space
Browse files Browse the repository at this point in the history
  • Loading branch information
p_caiwfeng authored and ginuerzh committed Apr 7, 2022
1 parent 11d4838 commit ffecc46
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tuntap_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func createTun(cfg TunConfig) (conn net.Conn, itf *net.Interface, err error) {
return
}

cmd := fmt.Sprintf("netsh interface ip set address name=%s "+
cmd := fmt.Sprintf("netsh interface ip set address name=\"%s\" "+
"source=static addr=%s mask=%s gateway=none",
ifce.Name(), ip.String(), ipMask(ipNet.Mask))
log.Log("[tun]", cmd)
Expand Down Expand Up @@ -70,7 +70,7 @@ func createTap(cfg TapConfig) (conn net.Conn, itf *net.Interface, err error) {
}

if ip != nil && ipNet != nil {
cmd := fmt.Sprintf("netsh interface ip set address name=%s "+
cmd := fmt.Sprintf("netsh interface ip set address name=\"%s\" "+
"source=static addr=%s mask=%s gateway=none",
ifce.Name(), ip.String(), ipMask(ipNet.Mask))
log.Log("[tap]", cmd)
Expand Down Expand Up @@ -105,7 +105,7 @@ func addTunRoutes(ifName string, gw string, routes ...IPRoute) error {

deleteRoute(ifName, route.Dest.String())

cmd := fmt.Sprintf("netsh interface ip add route prefix=%s interface=%s store=active",
cmd := fmt.Sprintf("netsh interface ip add route prefix=%s interface=\"%s\" store=active",
route.Dest.String(), ifName)
if gw != "" {
cmd += " nexthop=" + gw
Expand All @@ -127,7 +127,7 @@ func addTapRoutes(ifName string, gw string, routes ...string) error {

deleteRoute(ifName, route)

cmd := fmt.Sprintf("netsh interface ip add route prefix=%s interface=%s store=active",
cmd := fmt.Sprintf("netsh interface ip add route prefix=%s interface=\"%s\" store=active",
route, ifName)
if gw != "" {
cmd += " nexthop=" + gw
Expand All @@ -142,7 +142,7 @@ func addTapRoutes(ifName string, gw string, routes ...string) error {
}

func deleteRoute(ifName string, route string) error {
cmd := fmt.Sprintf("netsh interface ip delete route prefix=%s interface=%s store=active",
cmd := fmt.Sprintf("netsh interface ip delete route prefix=%s interface=\"%s\" store=active",
route, ifName)
args := strings.Split(cmd, " ")
return exec.Command(args[0], args[1:]...).Run()
Expand Down

0 comments on commit ffecc46

Please sign in to comment.