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: David Empson
Subject: Re: [lwip-users] Setting source port number for UDP send
Date: Fri, 11 Dec 2009 12:00:02 +1300

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.
 
----- Original Message -----
Sent: Friday, December 11, 2009 11:15 AM
Subject: [lwip-users] Setting source port number for UDP send

Hi to all,

i'm looking for a way to set the source port of an UDP send to a defined number, it seems that lwIP chooses this number randomly. Is there a way to set a value in the netbuf or the netconn to a defined port number in my UDP send part?

        netconn_connect(tftptxcon,&modsrv_addr,ip_data_out.port);    // Open connection
        tftpsrvbuf=netbuf_new();        // Create netbuf
        txdata=netbuf_ref(tftpsrvbuf,ip_data_out.buf,ip_data_out.ptr);    // Assign the data
        netconn_send(tftptxcon,tftpsrvbuf);        // Send the UDP data
        netconn_delete(tftptxcon);        // Delete the connection
        netbuf_delete(tftpsrvbuf);    // Delete the netbuf

Thank you all for your ideas!

Marco

reply via email to

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