Skip to content

Commit

Permalink
Fix build breaks on Plan9 and Solaris.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpal committed Nov 11, 2023
1 parent ddcc04d commit 9989e23
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ Pull requests for other OSs happily considered!

## Versions

### v1.0.13

+ Add tools/check-cross-compile.sh to check that the code compiles for various OSs.
+ Fix compilation errors exposed by tools/check-cross-compile.sh.

### v1.0.12

+ If there are multiple default gateways, Windows now returns the gateway with the lowest metric.
+ Fix solaris build break. (In theory, IDK how to test this easily.)
+ upgrade to golang 1.21
+ Upgrade to golang 1.21
+ Upgrade golang.org/x/net version, makes dependabot happy. Probably was not any actual security
issue because gateway doesn't use any of the APIs of golang.org/x/net that had security issues.

Expand Down
6 changes: 3 additions & 3 deletions gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type ErrNoGateway struct{}
// ErrCantParse is returned if the route table is garbage.
type ErrCantParse struct{}

// ErrNotImpemented is returned if your operating system
// ErrNotImplemented is returned if your operating system
// is not supported by this package. Please raise an issue
// to request support.
type ErrNotImpemented struct{}
type ErrNotImplemented struct{}

// ErrInvalidRouteFileFormat is returned if the format
// of /proc/net/route is unexpected on Linux systems.
Expand All @@ -33,7 +33,7 @@ func (*ErrCantParse) Error() string {
return "can't parse route table"
}

func (*ErrNotImpemented) Error() string {
func (*ErrNotImplemented) Error() string {
return "not implemented for OS: " + runtime.GOOS
}

Expand Down
2 changes: 1 addition & 1 deletion gatewayForBSDs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build darwin || dragonfly || freebsd || netbsd || openbsd || solaris
//go:build darwin || dragonfly || freebsd || netbsd || openbsd

package gateway

Expand Down
10 changes: 8 additions & 2 deletions gateway_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ package gateway

import (
"net"
"os/exec"
)

func readNetstat() ([]byte, error) {
routeCmd := exec.Command("netstat", "-rn")
return routeCmd.CombinedOutput()
}

func discoverGatewayOSSpecific() (ip net.IP, err error) {
bytes, err = readNetstat()
bytes, err := readNetstat()
if err != nil {
return nil, err
}
Expand All @@ -17,7 +23,7 @@ func discoverGatewayOSSpecific() (ip net.IP, err error) {
}

func discoverGatewayInterfaceOSSpecific() (ip net.IP, err error) {
bytes, err = readNetstat()
bytes, err := readNetstat()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions gateway_unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

func discoverGatewayOSSpecific() (ip net.IP, err error) {
return ip, errNotImplemented
return ip, &ErrNotImplemented{}
}

func discoverGatewayInterfaceOSSpecific() (ip net.IP, err error) {
return nil, errNotImplemented
return nil, &ErrNotImplemented{}
}
21 changes: 21 additions & 0 deletions tools/check-cross-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

TOP_DIR=${SCRIPT_DIR}/..

cd ${TOP_DIR}

# Check that tests pass on local os / architecture.

go test ./...

# Check that the library builds on all supported OSs.
#
# Note that "plan9" is in this list to test gateway_unimplemented.go
for os in "darwin" "dragonfly" "freebsd" "netbsd" "openbsd" "plan9" "solaris" "windows"
do
GOOS=${os} GOARCH=amd64 go build
done

0 comments on commit 9989e23

Please sign in to comment.