1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// +build linux
package gateway
import (
"fmt"
"io/ioutil"
"net"
"os"
)
const (
// See http://man7.org/linux/man-pages/man8/route.8.html
file = "/proc/net/route"
)
func discoverGatewayOSSpecific() (ip net.IP, err error) {
f, err := os.Open(file)
if err != nil {
return nil, fmt.Errorf("Can't access %s", file)
}
defer f.Close()
bytes, err := ioutil.ReadAll(f)
if err != nil {
return nil, fmt.Errorf("Can't read %s", file)
}
return parseLinuxGatewayIP(bytes)
}
func discoverGatewayInterfaceOSSpecific() (ip net.IP, err error) {
f, err := os.Open(file)
if err != nil {
return nil, fmt.Errorf("Can't access %s", file)
}
defer f.Close()
bytes, err := ioutil.ReadAll(f)
if err != nil {
return nil, fmt.Errorf("Can't read %s", file)
}
return parseLinuxInterfaceIP(bytes)
}
|