Skip to content

Commit

Permalink
access android name servers from SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginder-Singh committed Nov 21, 2024
1 parent 510698f commit ecd6d91
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
9 changes: 5 additions & 4 deletions cmd/cli/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cli
// AppCallback provides hooks for injecting certain functionalities
// from mobile platforms to main ctrld cli.
type AppCallback struct {
HostName func() string
LanIp func() string
MacAddress func() string
Exit func(error string)
HostName func() string
LanIp func() string
MacAddress func() string
AndroidNameServers func() []string
Exit func(error string)
}

// AppConfig allows overwriting ctrld cli flags from mobile platforms.
Expand Down
12 changes: 11 additions & 1 deletion cmd/cli/prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,20 @@ func (p *prog) preRun() {
}
}

// androidNameServers Only way to access system resolvers on android is through SDK.
// due to proc/net access not permitted.
func (p *prog) androidNameServers() []string {
if isAndroid() {
return p.appCallback.AndroidNameServers()
} else {
return nil
}
}

func (p *prog) postRun() {
if !service.Interactive() {
p.resetDNS()
ns := ctrld.InitializeOsResolver()
ns := ctrld.InitializeOsResolver(p.androidNameServers())
mainLog.Load().Debug().Msgf("initialized OS resolver with nameservers: %v", ns)
p.setDNS()
p.csSetDnsDone <- struct{}{}
Expand Down
4 changes: 4 additions & 0 deletions cmd/ctrld_library/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type AppCallback interface {
Hostname() string
LanIp() string
MacAddress() string
AndroidNameServers() []string
Exit(error string)
}

Expand Down Expand Up @@ -55,6 +56,9 @@ func mapCallback(callback AppCallback) cli.AppCallback {
MacAddress: func() string {
return callback.MacAddress()
},
AndroidNameServers: func() []string {
return callback.AndroidNameServers()
},
Exit: func(err string) {
callback.Exit(err)
},
Expand Down
8 changes: 6 additions & 2 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ func availableNameservers() []string {
//
// It's the caller's responsibility to ensure the system DNS is in a clean state before
// calling this function.
func InitializeOsResolver() []string {
return initializeOsResolver(availableNameservers())
func InitializeOsResolver(androidNameServers []string) []string {
if androidNameServers != nil {
return initializeOsResolver(androidNameServers)
} else {
return initializeOsResolver(availableNameservers())
}
}
func initializeOsResolver(servers []string) []string {
var (
Expand Down

0 comments on commit ecd6d91

Please sign in to comment.