Skip to content

Commit 1b77b1a

Browse files
committed
Add OSX version check
1 parent 4851555 commit 1b77b1a

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
func main() {
10+
// TODO: add support for specific host/port.
1011
mode := flag.String("mode", throttler.Start, "start or stop packet controls")
1112
latency := flag.Int("latency", -1, "latency to add in ms")
1213
bandwidth := flag.Int("bandwidth", -1, "bandwidth limit in kb/s")

throttler/throttler.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ package throttler
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"runtime"
8+
"strings"
79
)
810

911
const (
10-
Start = "start"
11-
stop = "stop"
12-
any = "any"
12+
Start = "start"
13+
stop = "stop"
14+
any = "any"
15+
linux = "linux"
16+
darwin = "darwin"
17+
freebsd = "freebsd"
18+
checkOSXVersion = "sw_vers -productVersion"
1319
)
1420

1521
type config struct {
@@ -66,9 +72,15 @@ func Run(mode string, latency, bandwidth int, packetLoss float64) {
6672

6773
var throttler throttler
6874
switch runtime.GOOS {
69-
case "darwin":
75+
case darwin, freebsd:
76+
if runtime.GOOS == darwin && !osxVersionSupported() {
77+
// ipfw was removed in OSX 10.10 in favor of pfctl.
78+
// TODO: add support for pfctl.
79+
fmt.Println("I don't support your version of OSX")
80+
os.Exit(1)
81+
}
7082
throttler = &ipfwThrottler{}
71-
case "linux":
83+
case linux:
7284
throttler = &tcThrottler{}
7385
default:
7486
fmt.Printf("I don't support your OS: %s\n", runtime.GOOS)
@@ -86,3 +98,11 @@ func Run(mode string, latency, bandwidth int, packetLoss float64) {
8698
os.Exit(1)
8799
}
88100
}
101+
102+
func osxVersionSupported() bool {
103+
v, err := exec.Command("/bin/sh", "-c", checkOSXVersion).Output()
104+
if err != nil {
105+
return false
106+
}
107+
return !strings.HasPrefix(string(v), "10.10")
108+
}

0 commit comments

Comments
 (0)