(payload []byte)
| 124 | } |
| 125 | |
| 126 | func (r *udpStackResponder) Write(payload []byte) (int, error) { |
| 127 | // set checksums and lengths |
| 128 | r.udpheader.SetNetworkLayerForChecksum(r.ipv4header) |
| 129 | |
| 130 | // log |
| 131 | verbosef("sending udp packet to subprocess: %s", summarizeUDP(r.ipv4header, r.udpheader, payload)) |
| 132 | |
| 133 | // serialize the data |
| 134 | packet, err := serializeUDP(r.ipv4header, r.udpheader, payload, r.stack.buf) |
| 135 | if err != nil { |
| 136 | return 0, fmt.Errorf("error serializing UDP packet: %w", err) |
| 137 | } |
| 138 | |
| 139 | // make a copy because the same buffer will be re-used |
| 140 | cp := make([]byte, len(packet)) |
| 141 | copy(cp, packet) |
| 142 | |
| 143 | // send to the subprocess channel non-blocking |
| 144 | select { |
| 145 | case r.stack.toSubprocess <- cp: |
| 146 | default: |
| 147 | return 0, fmt.Errorf("channel for sending udp to subprocess would have blocked") |
| 148 | } |
| 149 | |
| 150 | // return number of bytes passed in, not number of bytes sent to output |
| 151 | return len(payload), nil |
| 152 | } |
nothing calls this directly
no test coverage detected