Closed ssrshz closed 2 years ago
The data slice's total length is offset+mtu
then we read n bytes from Read. also, len(data[offset : offset+n]) == n
The data slice's total length is offset+mtu
then we read n bytes from Read. also, len(data[offset : offset+n]) == n
Oh,but i think the n bytes from Read starts with the “offset” bytes,and data[offset : offset+n] exceeds the length of n. Maybe I understand wrong?
and data[offset : offset+n] exceeds the length of n.
No, it doesn't.
Read returns total length it read, regardless of offset. it overwrites offset bytes first.
and data[offset : offset+n] exceeds the length of n.
No, it doesn't.
Read returns total length it read, regardless of offset. it overwrites offset bytes first.
er,i see.tks @xjasonlyu I'm learning tun2socks recently,this is a great project
When i debug here, i see all:
and data[offset : offset+n] exceeds the length of n.
No, it doesn't. Read returns total length it read, regardless of offset. it overwrites offset bytes first.
er,i see.tks @xjasonlyu I'm learning tun2socks recently,this is a great project
That's 4 bytes TUN PI header (offset).
https://github.com/xjasonlyu/tun2socks/blob/3926f866138b645948ad69ccfa03d97786df3fa8/core/device/iobased/endpoint.go#L113
according to the context,the data‘s max actual length is n,but here is [offset+n]: n, err := e.rw.Read(data)