-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add android os Allthough android is linux the 'ip route' command doesn't return 'default' line. Android has only one interface active at any time.
- Loading branch information
Showing
5 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sockaddr | ||
|
||
import ( | ||
"errors" | ||
"os/exec" | ||
) | ||
|
||
type routeInfo struct { | ||
cmds map[string][]string | ||
} | ||
|
||
// NewRouteInfo returns a Android-specific implementation of the RouteInfo | ||
// interface. | ||
func NewRouteInfo() (routeInfo, error) { | ||
return routeInfo{ | ||
cmds: map[string][]string{"ip": {"/system/bin/ip", "route", "get", "8.8.8.8"}}, | ||
}, nil | ||
} | ||
|
||
// GetDefaultInterfaceName returns the interface name attached to the default | ||
// route on the default interface. | ||
func (ri routeInfo) GetDefaultInterfaceName() (string, error) { | ||
out, err := exec.Command(ri.cmds["ip"][0], ri.cmds["ip"][1:]...).Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
|
||
var ifName string | ||
if ifName, err = parseDefaultIfNameFromIPCmdAndroid(string(out)); err != nil { | ||
return "", errors.New("No default interface found") | ||
} | ||
return ifName, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !android | ||
|
||
package sockaddr | ||
|
||
import ( | ||
|