title: Converting bytes from UDP Server
body: <p>I am creating a windows UDP tunnel using wintun driver. I have written a code to receive data from the server and send it to the windows tunnel using the function send_packet and allocatesendpacket. The error I get is that I can read data only as bytes from the UDP server but it causes a mismatch when I pass it to the send_packet function. The error is as follows:</p>
  <pre><code>mismatched types
  expected struct `wintun::Packet`, found `&amp;[u8]`
  </code></pre>
  <p>Code for send_packet and allocatesendpacket
  <a href="https://github.com/nulldotblack/wintun/blob/main/src/session.rs" rel="nofollow noreferrer">https://github.com/nulldotblack/wintun/blob/main/src/session.rs</a></p>
  <p>Code for packet struct data type
  <a href="https://github.com/nulldotblack/wintun/blob/main/src/packet.rs" rel="nofollow noreferrer">https://github.com/nulldotblack/wintun/blob/main/src/packet.rs</a></p>
  <p>Link for other dependencies
  <a href="https://github.com/nulldotblack/wintun" rel="nofollow noreferrer">https://github.com/nulldotblack/wintun</a></p>
  <p>How do I convert the bytes (variable buffer below) to Packet struct data type?. The error of mismatch occurs when I declare the value of a variable packet with the value of the received buffer variable, so that packet variable can be sent to tunnel.</p>
  <p>My code:</p>
  <pre><code>    let socket = UdpSocket::bind(&quot;6.0.0.1:8000&quot;) //create client socket object with ip and port
                         .expect(&quot;Could not bind client socket&quot;);
  
      socket.connect(&quot;6.0.0.10:8888&quot;) //SERVER IP /PORT
  
  let writer_session = session.clone();
  let writer =
   std::thread::spawn(move || {
      info!(&quot;Starting writer&quot;);
  
      while RUNNING.load(Ordering::Relaxed) {
          let mut buffer = [0u8; 20000]; 
                  socket.recv_from(&amp;mut buffer) //get message from server
                       .expect(&quot;Could not read into buffer&quot;);
          let leng1 = buffer.len();
  
  
  
                  let mut packet = writer_session.allocate_send_packet(leng1.try_into().unwrap()).unwrap();
                  packet = &amp;buffer[0..leng1];  //ERROR occurs here
                  writer_session.send_packet(packet);
                      
      }
  });
  </code></pre>