Giter Site home page Giter Site logo

Comments (2)

smartalock avatar smartalock commented on June 23, 2024

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;

from wireguard-lwip.

ruienk avatar ruienk commented on June 23, 2024

Thank you very much, your answer helped me to solve my problem :)

from wireguard-lwip.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.