UDP sockets not receive multicast messages on the same host - windows

I have two programs.
Program 1. This program creates one socket per network interface, sets the default multicast interface ID for this socket and bind it to the "interface_addr:some_port". Program listens its sockets and process received data.
Program 1 was tested and it receives multicasts from network devices.
Program 2. This program creates one socket per network interface and sends multicast requests and process replies.
Program 2 was tested - it receives replies for multicast requests from network devices.
The problem is that when both programs runned on the one host program 1 not see requests from program 2, but Wireshark shows the packets from program 2.
OS: Windows 7.
What I'm doing wrong?

You don't need multiple sockets. Bind a single socket to INADDR_ANY, and join the group via each interface in turn.

The problem was solved. There is only need to turn on option MULTICAST_LOOP both on the client and server

Related

UDP Packets not Sending Possibly Due to Client Not Found?

I have an application that is very simple. It sends out UDP packets to a client somewhere else on the network.
The host computer is 192.168.11.66 (Windows 10), the client device is 192.168.11.65 (proprietary device).
The host pc cannot see the client device, however I know that it is on and listening to traffic. When I send UDP packets from the host, I use Wireshark and I do not see the packets being sent out. Instead I see messages from ARP trying to locate the client. I assume because ARP is unsuccessful, the host cancels the sending of the packets.
If I change the destination address of the packets to a broadcast address, all of the packets get sent and I see everything on Wireshark. I need to be able to specify the IP address of the client and have Windows send the packets regardless of whether or not it thinks the client device is on the network or not. The client device looks for UDP traffic specifically addressed to itself and the client device has no way of making itself visible on the network.
Does anyone know how to work around this?
Thank you #Remy: instead to create your own ARP record manually. – Remy Lebeau
I did not realize that I could create manual entries in the ARP. I need to read more about ARP. Adding a manual entry solved my issue. I found that you could do it using ASP -s, or add neighbor using NETSH .
Thanks!

Golang cannot send packets to stun received ip

I’m using Golang to try to send packets through UDP to an IP address and port provided by STUN. The goal is to communicate between two devices without having to open a port in the firewall, as both devices are located in a different network.
The program runs on both devices in the following manner:
Device 1 waits for device 2 to send the IP address and port found by STUN. This goes through an open port in the firewall of device 1. (Only for device 1 an open port is possible)
The problem is that device 2 does not receive any packets through the port found by STUN.
I think the problem consists of the router not knowing the connection to device 2. Device 2 is connected with the router, but the router doesn’t know what to do with the packets.
Do you have any idea how to solve this problem?
Thanks!

PF_PACKET socket and 'Port unreachable' ICMP messages

My application needs to receive UDP packets from multiple destination ports (this is a bonafide application and not a sniffer). Therefore, I have chosen to use a PF_PACKET socket and to do port filtering at the application level.
Here's how I create the socket:
int g_rawSocket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
I am correctly receiving UDP packets. However, the kernel on which the application runs is sending ICMP packets of type 'Destination unreachable' and code 'Port unreachable' to the remote device that is sending packets to my app. I guess that this is because I have not bound a port number to the socket. However, I wonder if it is appropriate to use bind with a PF_PACKET socket, especially as I need to bind multiple ports to it, which I guess is not possible.
Any comments please?
No, it can't be bound to a specific port, since it's working on a lower level than the Transport (UDP/TCP) layer. However, you could open and listen to all sockets, using regular UDP (AF_INET/SOCK_DGRAM) sockets and select for example and as far as I know you can bind and listen to as many sockets as you want, as long as you don't exceed the limits of open file descriptors for your process.
I have also done the same thing in my application.
in my case i have created sockets as many i need & bind them with the particular port. but i m not listening to any socket. so i created one raw socket
int sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_UDP);
& then received all the traffic without any ICMP.
So i think u have to bind all the ports to avoid ICMP either you have to some kernel hacking as stoping or removing the code for ICMP in the linux-kernel code & build it again

How to receive the same udp-stream in several programs?

I have a closed third party system that sends a unicast UDP stream (MPEG-TS) that I'd like to access in two different programs on the same computer. I can not change anything on the source, not even IP or Port.
Is there any other option than to write my own little program that captures the stream and then creates to new streams and resends both?
It seems that only one of the two destination programs handles multicast, so I need two unicast streams.
You should be able to use socat to forward unicast UDP to a multicast group, or just save data into a file and process later.
Edit 0:
Here is an example (this is on Linux - don't have any Windows boxes). Listen on unicast port 4242, forward to multicast 224.10.10.10:5252 (you might have to add ip-multicast-loop option if you are doing everything on the same machine):
~$ socat UDP-LISTEN:4242 UDP-DATAGRAM:224.10.10.10:5252
Receive on multicast (needs interface address or name), forwards to unicast 192.168.0.1:6666:
~$ socat UDP-RECVFROM:5252,ip-add-membership=224.10.10.10:eth0,reuseaddr,fork \
UDP-DATAGRAM:192.168.0.1:6666
Run two of the above with different destination addresses (reuseaddr option allows these to be run on the same machine).

Send UDP broadcast on Windows 7

I have a PC with two network cards connected to different networks (multi homed network setup). I want to send UDP broadcast frames on both networks. The senders IP address of the frames must be the IP address of the adapter, that is used to send the frame. The destination address should be the LIMITED BROADCAST address.
The customer application should not run with administrative rights (UAC is not acceptible).
How can I send these UDP frames to the LIMITED BROADCAST address (255.255.255.255)?
How could I send these frames to the NETWORK BROADCAST address (x.y.z.255)?
I know how to do this with raw sockets. But raw sockets can only be used with administrative rights.
Can't you just open two normal UDP sockets and bind one to each of the interface addresses and then simply send to the broadcast addresses ?
This will, as far as I know, deal with the sending on both networks and it will ensure that the packets sent will have the correct ip address. It wont work if you bind a single socket to INADDR_ANY which, of course, WILL work if there's only a single network adapter in the machine. To create a complete solution it's probably best to iterate over the available addresses and create a socket for each, bind to each and send from each.

Resources