lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Setting source port number for UDP send


From: Marco Jakobs
Subject: Re: [lwip-users] Setting source port number for UDP send
Date: Fri, 11 Dec 2009 08:08:03 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Thanks for your thoughts, David!

I figured it out how to set a defined source port (in my case 69): Just insert this line to change the local port in the pcb:

        netconn_connect(tftptxcon,&modsrv_addr,ip_data_out.port);    // Open connection
        tftptxcon->pcb.udp->local_port=69;   // Set local (source) port
        tftpsrvbuf=netbuf_new();        // Create netbuf
          .....



David Empson schrieb:
With the raw API, the trick is to use udp_bind() to bind the PCB to a specified local IP address and port.
 
It looks like netconn_bind() will achieve the same thing for the netconn API, and lwip_bind() for the sockets API.
 
In each case, the bind is done after creating the PCB with the appropriate "new" call, before doing the first send/sendto/sendto_if.
 
Judging from a comment in api_lib.c, it isn't clear whether you can safely re-bind an existing PCB, so you might need to destroy the PCB and recreate it if you need to change your source port.
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]