Recv fetches the next packet into buf. Returns the number of bytes and the address metadata. On error, n is undefined.
(h handleRaw, buf []byte)
| 118 | // Recv fetches the next packet into buf. Returns the number of bytes and |
| 119 | // the address metadata. On error, n is undefined. |
| 120 | func Recv(h handleRaw, buf []byte) (n uint32, addr Address, err error) { |
| 121 | var recvLen uint32 |
| 122 | r1, _, e1 := procWinDivertRecv.Call( |
| 123 | uintptr(h), |
| 124 | uintptr(unsafe.Pointer(&buf[0])), |
| 125 | uintptr(uint32(len(buf))), |
| 126 | uintptr(unsafe.Pointer(&recvLen)), |
| 127 | uintptr(unsafe.Pointer(&addr)), |
| 128 | ) |
| 129 | if r1 == 0 { |
| 130 | return 0, addr, fmt.Errorf("WinDivertRecv: %w", translateErr(e1)) |
| 131 | } |
| 132 | return recvLen, addr, nil |
| 133 | } |
| 134 | |
| 135 | // Send writes packet pkt back to the stack using addr as the re-injection |
| 136 | // metadata. Returns bytes written. |
no test coverage detected