Skip to content

Commit

Permalink
Support Android 11 net.Interface
Browse files Browse the repository at this point in the history
Fix netlink permission issue by using anet wrapper
to get net interface and addresses.
  • Loading branch information
suutaku authored and edaniels committed Jul 22, 2024
1 parent 7cf567b commit 32e0017
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/pion/logging v0.2.2
github.com/stretchr/testify v1.9.0
github.com/wlynxg/anet v0.0.1
golang.org/x/net v0.26.0
golang.org/x/sys v0.22.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wlynxg/anet v0.0.1 h1:VbkEEgHxPSrRQSiyRd0pmrbcEQAEU2TTb8fb4DmSYoQ=
github.com/wlynxg/anet v0.0.1/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
Expand Down
9 changes: 5 additions & 4 deletions stdnet/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"

"github.com/pion/transport/v3"
"github.com/wlynxg/anet"
)

const (
Expand Down Expand Up @@ -38,15 +39,15 @@ var _ transport.Net = &Net{}
func (n *Net) UpdateInterfaces() error {
ifs := []*transport.Interface{}

oifs, err := net.Interfaces()
oifs, err := anet.Interfaces()

Check warning on line 42 in stdnet/net.go

View check run for this annotation

Codecov / codecov/patch

stdnet/net.go#L42

Added line #L42 was not covered by tests
if err != nil {
return err
}

for _, oif := range oifs {
ifc := transport.NewInterface(oif)
for i := range oifs {
ifc := transport.NewInterface(oifs[i])

Check warning on line 48 in stdnet/net.go

View check run for this annotation

Codecov / codecov/patch

stdnet/net.go#L47-L48

Added lines #L47 - L48 were not covered by tests

addrs, err := oif.Addrs()
addrs, err := anet.InterfaceAddrsByInterface(&oifs[i])

Check warning on line 50 in stdnet/net.go

View check run for this annotation

Codecov / codecov/patch

stdnet/net.go#L50

Added line #L50 was not covered by tests
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion stdnet/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestStdNet(t *testing.T) {
return
}

log.Debugf("interfaces: %+v", interfaces)
log.Debugf("interfaces: %+v", interfaces)
for _, ifc := range interfaces {
if ifc.Name == lo0String {
_, err := ifc.Addrs()
Expand Down

0 comments on commit 32e0017

Please sign in to comment.