Lwip TCP Server

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Brendan_Johnson
Level 2
Level 2
10 replies posted 25 sign-ins 5 questions asked
Dear sir / madam,
 
the follwing code works fine when the ETH LWIP, IP option "DCHP" is switched off.
However when "DHCP" is switched ON the server doesnt seem to listen / bind to the IP address & port?
Are there any commands I need to workaround this?
 
I'm using DHCP for the TCP client so it automatically abtains an IP address, however it stops the server working?
Many thanks in advance.
Brendan
 
 
void init_tcp_server(void)
{
err_t err_val;
ip_addr_t my_ip;
 
tcp_server.pcb = tcp_new(); // create tcp pcb (pcb = protocol control block) Listening Server
IP4_ADDR(&my_ip, 192, 168, 16, 151); // set my ip address.
 
if (tcp_server.pcb != NULL)
{
//IP_ADDR_ANY
err_val = tcp_bind(tcp_server.pcb, &my_ip, 50000);
if (err_val == ERR_OK)
{
// start tcp listening for echo_pcb
tcp_server.pcb = tcp_listen(tcp_server.pcb);
// initialize LwIP tcp_accept callback function
tcp_accept(tcp_server.pcb, &tcp_server_accept);
 
 
}
else
{
// deallocate the pcb
memp_free(MEMP_TCP_PCB, tcp_server.pcb);
}
}
}
0 Likes
1 Solution

Hi @Brendan_Johnson 

Please find inlined comments,

1)  I guess then the TCP CLIENT and TCP SERVER have to have the same IP address assigned by DHCP?

>> No, it is not necessary . If your tcp_server is behind switch then ip route needs to add in switch . But if your tcp_server is in same subnet which your client is then you need not to worry. In either case both should able to ping each other.

2) is it possible to switch off DHCP to make the IP address static without re-compiling the software?

>> No , since you have enabled DHCP in LWIP stack , it expect DHCP IP address. So you need to recompile with DHCP disabled.

 

If you are not able to see DHCP packets in wireshark then check and make sure that both client and server in same subnet and they are pingable.

Thanks

Sujata 

View solution in original post

0 Likes
7 Replies
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hello @Brendan_Johnson ,

Can you confirm When DHCP option is set , whether your board has received IP address from DHCP server ?  You can capture packet using wireshark . Please follow below steps 

1> add code to print IP address in xmc board firmware.

2> check netstat -t output in your server side host and see session is established with board if ip address is configured by DHCP server. 

3> capture all packets when DHCP server is started on server to check if DHCP packet is send to client . Please make sure firewall is not blocking the port numbers 67, 68 used for  DHCP connection . If so please change firewall configuration and then capture packets.

Expected is we must see DHCP packet flow between server and DHCP client, if we don't see then check firewall configuration. Then we can debug further.

 

Thanks

Sujata 

 

 

0 Likes

Hi Sujata,

many thanks for your reply.

I havent managed to log the DCHP packets in wireshark yet, but I can confirm that when i connect my tcp client, the IP address assigned is 192.168.16.38.

If I then use the IP address 192.168.16.38 and connect to my tcp server it works fine.

However my next questions are:

1) Can the "tcp client" and "tcp server" have separate IP addresses, or do they have to be the same?

2) If I dont call the "tcp client" software, will the "tcp server" establish its own IP address via DCHP?

 

thanks

Brendan

 

 

0 Likes

Hi Sujata,

I have now managed to log the DHCP packets in wireshark by using the command "bootp", the IP address assigned is 192.168.16.38.

I've also obtained the network info from the Lwip Stack using the code as below:
 
network_info.mac_address = ETH_LWIP_0.eth_mac->address;
network_info.detected_ip_address._long_ = ETH_LWIP_0.xnetif->ip_addr.addr;
network_info.detected_subnet_mask._long_ = ETH_LWIP_0.xnetif->netmask.addr;
network_info.detected_gateway._long_ = ETH_LWIP_0.xnetif->gw.addr;

 

However my next questions are:

1)  I guess then the TCP CLIENT and TCP SERVER have to have the same IP address assigned by DHCP?

2) is it possible to switch off DHCP to make the IP address static without re-compiling the software?

many thanks

Brendan

0 Likes

Hi @Brendan_Johnson 

Please find inlined comments,

1)  I guess then the TCP CLIENT and TCP SERVER have to have the same IP address assigned by DHCP?

>> No, it is not necessary . If your tcp_server is behind switch then ip route needs to add in switch . But if your tcp_server is in same subnet which your client is then you need not to worry. In either case both should able to ping each other.

2) is it possible to switch off DHCP to make the IP address static without re-compiling the software?

>> No , since you have enabled DHCP in LWIP stack , it expect DHCP IP address. So you need to recompile with DHCP disabled.

 

If you are not able to see DHCP packets in wireshark then check and make sure that both client and server in same subnet and they are pingable.

Thanks

Sujata 

0 Likes

Ok thanks Sujata,

a shame that the software has to be re-compiled to Enable / Disable DHCP.

Regards

Brendan

 

0 Likes
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi @Brendan_Johnson ,

Let me know if i can close this thread if your doubts are addressed. 

Thanks

Sujata

0 Likes

Hi Sujata,

yes please close the the thread.

thanks

Brendan

0 Likes