Page 1 of 1

Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Wed Sep 14, 2022 8:04 pm
by mattia424
Hi, I am trying to send a UDP packet from a client installed on my PC to a STM32F429ZI card using the built-in ethernet. The communication is structured as follows:

UDP packet in broadcast
Source IP: 192.168.1.100
Recipient IP: 255.255.255.255
Source port: 55192
Recipient port: 5048
Content: Specific request

The first packet is received correctly by the STM32 board which validates its content and responds with a specific response.
Response packet from STM to PC in UDP
Source IP: 192.168.1.110
Recipient IP: 192.168.1.100
Source port: 5048
Recipient port: 55192

In this configuration, everything works correctly as the packets pass through the same network.
If I put the STM32 on the 192.168.2.110/24 network it correctly receives the broadcast packet, it tells me that it correctly sends the response packet but if I check with wireshark I do not see any packets passing through the network.

I entered
<code>
int response = serverUdp.endPacket ();
if (response) {Serial1.println ("Response packet sent");
} else Serial1.println ("Reply packet NOT sent");
</code>
so I see the return of the endPacket () function and it always responds with the value 1

Other information:
- The sketch I am using is very similar to: https://www.arduino.cc/reference/en/lib ... udp.write/
- In place of the <Ethernet.h> library I have added <EthernetWebServer_STM32.h>
- I also tried to connect the PC and the STM point-to-point to exclude the network
- Another commercial device that has the same function does not give problems so I suppose there are no network problems


Is there a solution to this problem? is it possible to send packets to different IPs regardless of the IP and network that has been set to the ethernet interface?

Thank you

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Wed Sep 14, 2022 8:31 pm
by GonzoG
If I remember correctly, your IP setup cannot work on 2 different subnets.
192.168.2.110/24 => IP mask 255.255.255.0, so 192.168.2.x subnet only.

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Wed Sep 14, 2022 8:37 pm
by ag123
not too familiar with this, but on stm32 it may not have a complete IP stack as like those on a PC or RPi.
e.g. it may not be possible to bind stm32 to 2 different IP address. But on your PC, it may be possible to do that.
Hence, one way is possibly that on your PC, you could configure the interface to have 2 ip address, on 2 different subnets.
While on the stm32 it stay on just a single IP address and subnet.

e.g.
PC
192.168.1.1/24
192.168.2.1/24 ---------------- STM32 192.168.2.100/24
^ the PC interface is bound to 2 IP address and 2 subnets

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Wed Sep 14, 2022 9:03 pm
by mattia424
ag123 wrote: Wed Sep 14, 2022 8:37 pm not too familiar with this, but on stm32 it may not have a complete IP stack as like those on a PC or RPi.
e.g. it may not be possible to bind stm32 to 2 different IP address. But on your PC, it may be possible to do that.
Hence, one way is possibly that on your PC, you could configure the interface to have 2 ip address, on 2 different subnets.
While on the stm32 it stay on just a single IP address and subnet.

e.g.
PC
192.168.1.1/24
192.168.2.1/24 ---------------- STM32 192.168.2.100/24
^ the PC interface is bound to 2 IP address and 2 subnets

I can't use your solution, the purpose of this is to have a utility on the PC that searches for devices on the network by scanning in broadcast, identifying them (even with IPs belonging to different networks) obviously connected to the same LAN / VLAN and then once I know the IP I can send another packet to the STM32 where I communicate another IP and I reinsert the STM32 into the PC network.

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Wed Sep 14, 2022 11:22 pm
by GonzoG
mattia424 wrote: Wed Sep 14, 2022 9:03 pm I can't use your solution, the purpose of this is to have a utility on the PC that searches for devices on the network by scanning in broadcast, identifying them (even with IPs belonging to different networks) obviously connected to the same LAN / VLAN and then once I know the IP I can send another packet to the STM32 where I communicate another IP and I reinsert the STM32 into the PC network.
But you need properly configured hardware for it to work (proper IP and mask).

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Thu Sep 15, 2022 3:57 am
by ag123
mattia424 wrote: Wed Sep 14, 2022 9:03 pm I can't use your solution, the purpose of this is to have a utility on the PC that searches for devices on the network by scanning in broadcast, identifying them (even with IPs belonging to different networks) obviously connected to the same LAN / VLAN and then once I know the IP I can send another packet to the STM32 where I communicate another IP and I reinsert the STM32 into the PC network.
In common 'network speak' the usual solutions are DHCP, BOOTP and MDNS, SSDP etc. Those can be done on stm32 side, but that you would need to program them yourself.

DHCP is a common way to dynamically obtain a valid network address, this is used for nearly every network device today.
https://en.wikipedia.org/wiki/Dynamic_H ... n_Protocol
MDNS is a broadcast DNS to allow clients/PCs to discover the device.
https://en.wikipedia.org/wiki/Multicast_DNS
SSDP is one further step that is common in UPnP devices:
https://en.wikipedia.org/wiki/Simple_Se ... y_Protocol

Re: Problem of sending UDP packet to a device belonging to another network but located within the same LAN.

Posted: Thu Jan 05, 2023 2:14 pm
by jellyopulent
GonzoG wrote: Wed Sep 14, 2022 11:22 pm But you need properly configured hardware for it to work (proper IP and mask).
True, I can not solve it yet.