0

I have an application that uses QUdpSocket to send broadcast packets. The machine sending the packets has several network interfaces.

Unfortunately, I haven't been able to figure out how to get QUdpSocket to use the right network interface. Is there an option somewhere that allows me to specify exactly which interface to use for sending the packets?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

2 Answers2

1

Every subnet has its own broadcast address. So I think you can send broadcast packets 'directly' to the addresses like 10.255.255.255 or 192.168.255.255.

hank
  • 9,553
  • 3
  • 35
  • 50
1

You are actually choosing which network to listen to in the first argument of bind function, address. If you are choosing for example QHostAddress::AnyIPv4 it means that no matter from which interface (better to say as a result of which IP address) the packet is received, the program should catch it. Otherwise you can enter an IP address (or a broadcast address) to which the packet should be sent.

For debugging and verification of it you can use netstat to list open ports as explained here: https://superuser.com/questions/529830/get-a-list-of-open-ports-in-linux

In the result of netstat command, Local Address is what you are looking for, specifying which address is being listened to.

NOTE: The address of localhost in Local Address (e.g.: 0.0.0.0 or 127.0.0.1) means any Local Address is acceptable.

Community
  • 1
  • 1
Sheric
  • 416
  • 2
  • 16