Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: More deep error messages #159

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion cmd/spoof-dpi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func main() {
} else {
util.PrintSimpleInfo()
}

if config.SystemProxy {
if err := util.SetOsProxy(uint16(config.Port)); err != nil {
logger.Fatal().Msgf("error while changing proxy settings: %s", err)
Expand Down
17 changes: 9 additions & 8 deletions util/os.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import (
"errors"
"fmt"
"os/exec"
"runtime"
Expand All @@ -23,7 +22,7 @@ func SetOsProxy(port uint16) error {

network, err := getDefaultNetwork()
if err != nil {
return err
return fmt.Errorf("failed to get default network: %w", err)
}

return setProxy(getProxyTypes(), network, "127.0.0.1", port)
Expand All @@ -36,20 +35,22 @@ func UnsetOsProxy() error {

network, err := getDefaultNetwork()
if err != nil {
return err
return fmt.Errorf("failed to get default network: %w", err)
}

return unsetProxy(getProxyTypes(), network)
}

func getDefaultNetwork() (string, error) {
network, err := exec.Command("sh", "-c", getDefaultNetworkCMD).Output()
cmd := exec.Command("sh", "-c", getDefaultNetworkCMD)
out, err := cmd.CombinedOutput()
if err != nil {
return "", err
} else if len(network) == 0 {
return "", errors.New("no available networks")
return "", fmt.Errorf("%s: %s", cmd.String(), out)
}
if len(out) == 0 {
return "", fmt.Errorf("%s: no available networks", cmd.String())
}
return strings.TrimSpace(string(network)), nil
return strings.TrimSpace(string(out)), nil
}

func getProxyTypes() []string {
Expand Down