Skip to content

Commit

Permalink
Fix stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertreat committed Oct 2, 2015
1 parent 9236e22 commit 58f1ecb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
20 changes: 13 additions & 7 deletions comcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"flag"
"log"
"fmt"
"net"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -31,7 +32,7 @@ func main() {
flag.Parse()

if *vers {
log.Printf("v%s", version)
fmt.Printf("Comcast version %s\n", version)
return
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
38 changes: 20 additions & 18 deletions throttler/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"log"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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 == "" {
Expand All @@ -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 {
Expand Down

0 comments on commit 58f1ecb

Please sign in to comment.