Sending UDP packet without routing

Hello,
I’m trying to do my discovery protocol (like the Digi’s ADDP), I send an UDP multicast packet (on 224.0.5.128).
If the pc and the Digi are on the same subnet all work fine, but when the they are on different subnets I can receive my multicast UDP packet but when I try to send a reply, the Digi starts to look for the gateway and after 5 attempts it fails.

An example from Wireshark:
10.118.1.249 is the pc
192.168.1.8 is the Digi
192.168.1.1 is the Digi’s gateway

This is the Digi ADDP discovery (it works on different subnets):
source | dest | protocol | info

(the ADDP discovery packet)
10.118.1.249 | 224.0.5.128 | UDP | Source port: gpfs Destination port: digiman
(here it looks for the gateway 3 times)
Digiboar_4c:c7:f2 | Broadcast | ARP | Who has 192.168.1.1? Tell 0.0.0.0
Digiboar_4c:c7:f2 | Broadcast | ARP | Who has 192.168.1.1? Tell 0.0.0.0
Digiboar_4c:c7:f2 | Broadcast | ARP | Who has 192.168.1.1? Tell 0.0.0.0
(then it sends the discovery reply)
192.168.1.8 | 10.118.1.249 | UDP | Source port: digiman Destination port: gpfs

This is my discovery:
source | dest | protocol | info

(the discovery packet, it is received correctly)
10.118.1.249 | 224.0.5.128 | UDP | Source port: 51611 Destination port: qadmifevent
(here it looks for the gateway 5 times then quits the sendto )
Digiboar_4c:cb:19 | Broadcast | ARP | Who has 192.168.1.1? Tell 192.168.1.8
Digiboar_4c:cb:19 | Broadcast | ARP | Who has 192.168.1.1? Tell 192.168.1.8
Digiboar_4c:cb:19 | Broadcast | ARP | Who has 192.168.1.1? Tell 192.168.1.8
Digiboar_4c:cb:19 | Broadcast | ARP | Who has 192.168.1.1? Tell 192.168.1.8
Digiboar_4c:cb:19 | Broadcast | ARP | Who has 192.168.1.1? Tell 192.168.1.8

Is there a way to send an UDP packet without searching the gateway?
(and why the ADDP ARPs have 0.0.0.0 as ip address?)

Thank you

Hello,
as usual, here’s my self-response.
I’m a novice at networking, you are warned.

A summary:

  • from a pc I send a search UDP packet to the multicast IP address 224.0.6.128 on port 2462
  • the Digis are instructed to join this multicast IP address: setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP… )
  • when a Digi receive a search packet it responds to the pc IP with all its information

This works, but there is a problem, if the pc is on another network when the Digi want to respond the TCP/IP stack it sees that the pc’ subnet is different and it searches for the gateway MAC address with an ARP request.
A solution can be to respond on the same IP multicast address (multicast addresses use some specials reserved MAC addresses 0x01,0x00,0x5E,XX,XX,XX), but the Digi does not recognize the multicast addresses 224.X.X.X and again it searches for the gateway.

I’ve tried ‘SO_DONTROUTE’ with the function ‘setsockopt()’: no luck
I’ve tried ‘MSG_DONTROUTE’ with the function ‘sendto()’: no luck

As charliek said here the only way is to manually create an UDP packet and send it bypassing the TCP/IP stack with function ‘na_eth_send()’.
You have to create the Ethernet header, the IP header, the UDP header and the payload, the only thing you can leave empty is the source MAC address in the Ethernet header.

Now, there is another problem, on the socket level you don’t known the pc’s MAC address. As said by ieftimovski here you need small a modification to eth_recv.c, but you can also solve this by replying on the multicast IP address. As said before, a multicast IP address is associated with a particular MAC address, mine is 0x01, 0x00, 0x5E, 0x00, 0x06, 0x80.

This works, but what if two Digis have the same IP addresses or if they are configured to use DHCP but there is no DHCP server?
In these cases then function setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP… ) fails, so we don’t listen to the pc searches.
To solve this you have to use the Ethernet bypass functionality even to receive. You have to register your bypass function with
‘NAEthRegisterCustomPacketFn()’, now all the packets are passed to this function, we can filter them and we can process them.

An example of the Ethernet bypass functions can be found here:
netos74\src\examples
abypassapp\root.c
netos74\src\examples
abypassapp\send.c

I’ve attached a ripped version of my sources (NET+OS 7.4.1, Connect Me), I hope it helps somebody. Use at your own risk.