[Top][All Lists]

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

Re: [lwip-users] Changing Port number at run time

From: Sanchayan
Subject: Re: [lwip-users] Changing Port number at run time
Date: Fri, 05 Oct 2012 08:45:07 +0530
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1


The use case is as follows.

Assume that your product uses lwip for communicating over TCP IP. Now, you want to access this particular device, from a remote location. Lets say you are in one part of the country, where in a particular LAN, this device is being used. One way of accessing this device from a remote location, would be to have the device get a static IP assigned. But, let's say there are N number of devices, it's not possible to assign each of them a static IP, as these would require a fixed annual charge from the ISP for each IP being used.

Now, consider a scenario where port number can be changed at run time. I assign each device a particular local IP, and each device is assigned a port number, which the customer wants. This port number has to be configurable. So, all these devices are now connected to a router. In the router configuration settings, the port number for each device is forwarded. For device x, say 2101 is forwarded and for device y, sat 2102 is forwarded. The router will be given a static IP. Now, assuming, let's say the router static IP address is you would be able to access the device x with and device y with

I wasn't aware lwiplib.c file was a part of the Stellaris port and not lwip. You are right Simon Goldschmidt.

I managed to change the port number, by doing this.

1. Send a command for changing the port number.
2. Then run the below code.

tcp_close(pcb);             //Close the pcb being used currently

pcb = tcp_new();         // Create a new pcb

tcp_bind( pcb, IP_ADDR_ANY, port_number ); // Bind the pcb to the new port number received from command

pcb = tcp_listen( pcb ); // Put the pcb in listen state

tcp_accept( pcb, connection_accept ); // Define the function for accepting connections

Now, this works. I can now connect to the device over the new port number. But, i can also connect to the device over the old port number, which was being used. Can this be prevented in some way. In my scenario, i guess i will not face any problems, as the router will take care of this, by binding the IP of the device to the port number and i won't get requests over the old port number, but, is there a way of preventing it?

Or should i do a system reset which will initialize my lwip stack anew with the new port number. The port number will be written to flash non volatile memory.

Thanks & Regards,
Sanchayan Maity.

On 03-10-2012 15:14, junix wrote:
Quoting Simon Goldschmidt <address@hidden>:

Sanchayan wrote:
I tried to see in lwiplib.c file, if there is a function like lwIPNetworkConfigChange(), which will help me change the port number for a particular connection.
I don't know that file, which suggests it is not part of lwIP itself but rather part of a specific lwIP port.
You are right. It's part of the Stellaris-Port that TI did. According to the documentation, the function he mentioned uses either netif_set_addr or does the DHCP stuff needed to get/change the IP-Adress:
//! This function will evaluate the new configuration data. If necessary, the //! interface will be brought down, reconfigured, and then brought back up
//! with the new configuration.

I have got a connection running in listening mode on a particular port. For giving Dynamic DNS provision, i need to change the port number of my listening connection at run time.
I don't understand this one. What exactly do you want to achieve? I don't yet get why you need to change the port number of your LISTENING port at runtime?


lwip-users mailing list

Disclaimer: This message (including any attachments) contains confidential information and is intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action based on the contents of this information is strictly prohibited. If you have received this email in error please notify address@hidden Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Godrej & Boyce Mfg. Co. Ltd. group of companies. The recipient should check this email and any attachments for the presence of viruses. Godrej & Boyce Mfg. Co. Ltd. group of companies accepts no liability for any damage caused by any virus transmitted by this email.

reply via email to

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