| 202 | } |
| 203 | |
| 204 | func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error) { |
| 205 | // TODO: the BSDs look very similar in Read() and Write(). They should be |
| 206 | // collapsed, with platform-specific files containing the varying parts of |
| 207 | // their implementations. |
| 208 | select { |
| 209 | case err := <-tun.errors: |
| 210 | return 0, err |
| 211 | default: |
| 212 | buf := bufs[0][offset-4:] |
| 213 | n, err := tun.tunFile.Read(buf[:]) |
| 214 | if n < 4 { |
| 215 | return 0, err |
| 216 | } |
| 217 | sizes[0] = n - 4 |
| 218 | return 1, err |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | func (tun *NativeTun) Write(bufs [][]byte, offset int) (int, error) { |
| 223 | if offset < 4 { |