Disabling UDP Self-Service

I want to know if there is a way to disable UDP broadcast from node A and not rcvd using node A. For braodcast, I just use INADDR_BROADCAST and on the rcvr side I use AI_PASSIVE | AI_NUMERICHOST.

Thanks Arpit

+2
source share
3 answers

No, this is a fundamental property of broadcasting - every host on the subnet, including the sender, will have to process the packet to the network stack. The following options are possible:

+2

, .

  #include <net/if.h>
  #include <socket.h>

  struct ifreq interface;
  strcpy(interface.ifr_ifrn.ifrn_name, "eth0");

  int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface));

  //... bind(fd,...) ...

, , ( ), .

+2

Python. , UDP , , , . IP- 192.168.2.1.

  • When binding to '192.168.2.255' or '' (empty address), the broadcaster receives sent messages by itself
  • When binding to '192.168.2.1', '255.255.255.255' or '<broadcast>', the broadcaster will NOT receive messages sent by themselves

The receiver received UDP broadcast messages in all of these cases.

PS Tested on Python 2.7.9, OS Raspbian 8 (Debian adaptation for Raspberry Pi), Linux kernel 4.4.38

+1
source

All Articles