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 a1b0b8e commit da99fc1
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.12
require (
github.com/pion/logging v0.2.2
github.com/stretchr/testify v1.8.4
github.com/wlynxg/anet v0.0.1
golang.org/x/net v0.14.0
golang.org/x/sys v0.11.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/wlynxg/anet v0.0.1 h1:VbkEEgHxPSrRQSiyRd0pmrbcEQAEU2TTb8fb4DmSYoQ=
github.com/wlynxg/anet v0.0.1/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
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/v2"
"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()
if err != nil {
return err
}

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

addrs, err := oif.Addrs()
addrs, err := anet.InterfaceAddrsByInterface(&oifs[i])
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 da99fc1

Please sign in to comment.