mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-14 04:54:36 +08:00
add go-tun2socks code
This commit is contained in:
18
common/route/route_linux.go
Normal file
18
common/route/route_linux.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func AddRoute(dest, netmask, gateway string) error {
|
||||
out, err := exec.Command("ip", "route", "add", dest+"/32", "via", gateway).Output()
|
||||
if err != nil {
|
||||
if len(out) != 0 {
|
||||
return errors.New(fmt.Sprintf("%v, output: %s", err, out))
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user