From 58f1ecb816f98e2f504c03a6687b3adecf52b0c7 Mon Sep 17 00:00:00 2001 From: Tyler Treat Date: Thu, 1 Oct 2015 19:30:56 -0500 Subject: [PATCH] Fix stdout --- comcast.go | 20 +++++++++++++------- throttler/throttler.go | 38 ++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/comcast.go b/comcast.go index 315fa3a..a300611 100644 --- a/comcast.go +++ b/comcast.go @@ -2,8 +2,9 @@ package main import ( "flag" - "log" + "fmt" "net" + "os" "strconv" "strings" @@ -31,7 +32,7 @@ func main() { flag.Parse() if *vers { - log.Printf("v%s", version) + fmt.Printf("Comcast version %s\n", version) return } @@ -59,7 +60,8 @@ func parseLoss(loss string) float64 { } l, err := strconv.ParseFloat(val, 64) if err != nil { - log.Fatalln("Incorrectly specified packet loss:", loss) + fmt.Println("Incorrectly specified packet loss:", loss) + os.Exit(1) } return l } @@ -87,7 +89,8 @@ func parseAddrs(addrs string) ([]string, []string) { parsedIPv6 = append(parsedIPv6, net.String()) } } else { - log.Fatalln("Incorrectly specified target IP or CIDR:", adr) + fmt.Println("Incorrectly specified target IP or CIDR:", adr) + os.Exit(1) } } } @@ -106,13 +109,15 @@ func parsePorts(ports string) []string { if validRange(prt) { parsed = append(parsed, prt) } else { - log.Fatalln("Incorrectly specified port range:", prt) + fmt.Println("Incorrectly specified port range:", prt) + os.Exit(1) } } else { //Isn't a range, check if just a single port if validPort(prt) { parsed = append(parsed, prt) } else { - log.Fatalln("Incorrectly specified port:", prt) + fmt.Println("Incorrectly specified port:", prt) + os.Exit(1) } } } @@ -172,7 +177,8 @@ func parseProtos(protos string) []string { p == "icmp" { parsed = append(parsed, p) } else { - log.Fatalln("Incorrectly specified protocol:", p) + fmt.Println("Incorrectly specified protocol:", p) + os.Exit(1) } } } diff --git a/throttler/throttler.go b/throttler/throttler.go index 72cad7b..63fe321 100644 --- a/throttler/throttler.go +++ b/throttler/throttler.go @@ -4,7 +4,6 @@ import ( "bufio" "errors" "fmt" - "log" "os" "os/exec" "runtime" @@ -56,30 +55,34 @@ var dry bool func setup(t throttler, cfg *Config) { if t.exists() { - log.Fatalln("It looks like the packet rules are already setup") + fmt.Println("It looks like the packet rules are already setup") + os.Exit(1) } if err := t.setup(cfg); err != nil { - log.Fatalln("I couldn't setup the packet rules: %s", err.Error()) + fmt.Println("I couldn't setup the packet rules: %s", err.Error()) + os.Exit(1) } - log.Println("Packet rules setup...") - log.Printf("Run `%s` to double check\n", t.check()) - log.Printf("Run `%s --stop` to reset\n", os.Args[0]) + fmt.Println("Packet rules setup...") + fmt.Printf("Run `%s` to double check\n", t.check()) + fmt.Printf("Run `%s --stop` to reset\n", os.Args[0]) } func teardown(t throttler, cfg *Config) { if !t.exists() { - log.Fatalln("It looks like the packet rules aren't setup") + fmt.Println("It looks like the packet rules aren't setup") + os.Exit(1) } if err := t.teardown(cfg); err != nil { - log.Fatalln("Failed to stop packet controls") + fmt.Println("Failed to stop packet controls") + os.Exit(1) } - log.Println("Packet rules stopped...") - log.Printf("Run `%s` to double check\n", t.check()) - log.Printf("Run `%s` to start\n", os.Args[0]) + fmt.Println("Packet rules stopped...") + fmt.Printf("Run `%s` to double check\n", t.check()) + fmt.Printf("Run `%s` to start\n", os.Args[0]) } // Run executes the packet filter operation, either setting it up or tearing @@ -98,7 +101,8 @@ func Run(cfg *Config) { switch runtime.GOOS { case freebsd: if cfg.Device == "" { - log.Fatalln("Device not specified, unable to default to eth0 on FreeBSD.") + fmt.Println("Device not specified, unable to default to eth0 on FreeBSD.") + os.Exit(1) } t = &ipfwThrottler{c} @@ -109,7 +113,8 @@ func Run(cfg *Config) { } else if c.commandExists(ipfw) { t = &ipfwThrottler{c} } else { - log.Fatalln("Could not determine an appropriate firewall tool for OSX (tried pfctl, ipfw), exiting") + fmt.Println("Could not determine an appropriate firewall tool for OSX (tried pfctl, ipfw), exiting") + os.Exit(1) } if cfg.Device == "" { @@ -122,12 +127,9 @@ func Run(cfg *Config) { } t = &tcThrottler{c} - case windows: - log.Fatalln("I don't support your OS: %s\n", runtime.GOOS) - //log.Fatalln("If you want to use Comcast on Windows, please install wipfw.") - //t = &wipfwThrottler{} default: - log.Fatalln("I don't support your OS: %s\n", runtime.GOOS) + fmt.Println("I don't support your OS: %s\n", runtime.GOOS) + os.Exit(1) } if !cfg.Stop {