Closed ruienk closed 1 year ago
The Wireguard LwIP code simply adds a new “netif” network interface to the LwIP stack. Once set up you use it exactly the same was as you would any other network interface.
e.g. if using the LwIP “raw” APIs (https://www.nongnu.org/lwip/2_1_x/group__callbackstyle__api.html) you would send a UDP packet using the udp_sendto() function (which would follow the normal LwIP interface selection algorithm), or to force traffic out a specific interface (e.g. the wg_netif one) you would use udp_sendto_if(…, …, wg_netif)
Your WireGuard server will decrypt the packet and then it is up to that server how it handles it - e.g. does it route it to your client directly? perform some form of NAT, etc
// Create a new UDP connection handle
struct udp_pcb *udp = udp_new();
if (!udp) {
return ERR_MEM;
}
// Allocate a packet buffer to hold packet data - e.g. 5 bytes of data for text
struct pbuf *udp_data = pbuf_alloc(PBUF_TRANSPORT, 5, PBUF_RAM);
if (!udp_data) {
return ERR_MEM;
}
// Populate the packet buffer with sample data
pbuf_take(udp_data, "Hello", 5);
// Choose where to send the UDP packet to
ip_addr_t dst_ip = IPADDR4_INIT_BYTES(192, 168, 1, 100);
u16_t dst_port = 1234;
// Send the packet out - specifically choose to send over the WireGuard interface for this example
err_t err = udp_sendto_if(udp, udp_data, &dst_ip, dst_port, wg_netif);
pbuf_free(udp_data);
return err;
Thank you very much, your answer helped me to solve my problem :)
Hello,
the WireGuard Handshake works fine and the keepalive pakets are fine too. i would like to send from my WireGuard-Client packets through the WireGuard-Tunnel to a target machine. But i dont know how... which function i have to call? My first Idea was:
But this packts will send directly to the target machine without going through the tunnel. There is also no encryption here.
My secound Idea was:
This is sending encrypted packets to the target machine, but not through the tunnel. That means my target machine receives encrypted data...
Can anyone explain me how i send packets from my WireGuard-Client packets through the WireGuard-Tunnel to my target machine? Which output function i have to call?
Best regards Ruien Karimi