Open wlynxg opened 3 months ago
Similar Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
The error comes from https://github.com/torvalds/linux/blob/e5b3efbe1ab1793bb49ae07d56d0973267e65112/net/ipv6/af_inet6.c#L364
In my code, I specified the zone name, and go needs to obtain the corresponding relationship between zone name and zone index from zoneCache
when parsing.
The data in zoneCache comes from
https://github.com/golang/go/blob/4f77a83589baa5a3038cc6e35615084dc7e5f0c1/src/net/interface.go#L217,
but because there is a problem when go calls interfaceTable on the Android side https://github.com/golang/go/issues/40569,
go fails when doing zone name -> zone index mapping, so in order to pass a valid zone id to the socket
I fixed this problem in anet: https://github.com/wlynxg/anet/commit/a8525cbb183e42802dcf57e39bd1daf26e771050
It might be possible to commit these changes to the standard library.
It might be possible to commit these changes to the standard library.
This is difficult in some ways because the changes are tied to the Android version.
The error comes from https://github.com/torvalds/linux/blob/e5b3efbe1ab1793bb49ae07d56d0973267e65112/net/ipv6/af_inet6.c#L364
In my code, I specified the zone name, and go needs to obtain the corresponding relationship between zone name and zone index from
zoneCache
when parsing. The data in zoneCache comes fromhttps://github.com/golang/go/blob/4f77a83589baa5a3038cc6e35615084dc7e5f0c1/src/net/interface.go#L217 , but because there is a problem when go calls interfaceTable on the Android side #40569, go fails when doing zone name -> zone index mapping, so in order to pass a valid zone id to the socket
I fixed this problem in anet: wlynxg/anet@a8525cb
How to get zone id ? I noticed that Android works with scope id for link local addresses not with zone name: https://developer.android.com/reference/java/net/Inet6Address
@vikulin The zone id is actually the index of the interface https://github.com/golang/go/blob/9d33956503c0d96c0c5666d374173f7ac9756d98/src/net/interface.go#L43. In fact, when passing the zone id, you can choose the name https://github.com/golang/go/blob/9d33956503c0d96c0c5666d374173f7ac9756d98/src/net/interface.go#L263 or directly pass the index https://github.com/golang/go/blob/9d33956503c0d96c0c5666d374173f7ac9756d98/src/net/interface.go#L267
@wlynxg I'm not sure that zone id is what I'm looking for. Obviously zone id = 46 is not the index since the Android device never had so many interfaces. Linux devices return interface names - this is where the difference. Code is expecting interface name but getting scope id.
nBytes, rcm, fromAddr, err := m.sock.ReadFrom(bs)
from := fromAddr.(*net.UDPAddr)
log.Infoln(from.String())
returns
[fe80::33d6:4970:9c23:5f7c%46]:9001
@vikulin The network card index numbers do not necessarily need to be in order, as long as they are unique. You can make your own rules. You can directly output iface.Index to view their ids. When using c for ipv6 socket, the zone id) passed is the index of the network.
@hyangah @ianlancetaylor
Go version
go version go1.20.11 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
What did you expect to see?
listen success