linux - UDP-Broadcast on all interfaces -
on linux system wired , wireless interface (e.g. 192.168.1.x , 192.168.2.x subnets) want send udp broadcast goes out via available interfaces (i.e. both through wired , wireless interface).
currently sendto() inaddr_broadcast, seems broadcast sent through 1 of interfaces (not same , subsequent broadcasts may use other interface).
is there way can send udp broadcast goes out through every single interface?
first of all, should consider broadcast obsolete, specially inaddr_broadcast
(255.255.255.255). question highlights 1 of reasons broadcast unsuitable. should die along ipv4 (hopefully). note ipv6 doesn't have concept of broadcast (multicast used, instead).
inaddr_broadcast
limited local link. nowadays, it's visible use dhcp auto-configuration, since @ such time, client not know yet in network connected to.
with single sendto()
, single packet generated, , outgoing interface determined operating system's routing table (ip route
on linux). can't have single sendto()
generate more 1 packet, have iterate on interfaces, , either use raw sockets or bind socket device using setsockopt(..., sol_socket, so_bindtodevice, "ethx")
send each packet bypassing os routing table (this requires root privileges). not solution.
instead, since inaddr_broadcast
not routed anyway, can achieve same thing iterating on each interface, , sending packet broadcast address. example, assuming networks have 255.255.255.0 (/24) masks, broadcast addresses 192.168.1.255 , 192.168.2.255. call sendto()
once each of these addresses , have accomplished goal.
edit: fixed information regarding inaddr_broadcast
, , complementing answer information so_bindtodevice
.