|
Different network segments are not broadcast
=============
How to use UDP to broadcast across network segments
Broadcast domains
First, let's understand the concept of the broadcast domain.
A broadcast domain is a collection of all hosts on a network that can receive broadcast frames from any host. That is, if one of the hosts in the broadcast domain emits a broadcast frame, all other hosts in the same broadcast domain can receive the broadcast frame.
Calculation of the broadcast domain
How do you know which broadcast domain a host belongs to? In fact, the calculation is very simple, as long as the IP address and subnet mask of the host are used to perform the calculation, you can know which broadcast domain the host belongs to. For example, if the IP address of a host is 192.168.23.150 and the subnet mask is 255.255.255.0, the broadcast domain to which it belongs is 192.168.23.150 & 255.255.255.0 = 192.168.23.0. Then all other hosts in the broadcast domain 192.168.23.0 can access the broadcast packets sent by the device. If you change the subnet mask to 255.255.0.0, then the broadcast domain to which it belongs is 192.168.23.150&255.255.0.0=192.168.0.0. All other hosts in the broadcast domain 192.168.0.0 can receive the broadcast packets sent by the device.
Calculation of broadcast addresses
In order to receive broadcast frames from other hosts in the same broadcast domain, you also need to specify the broadcast address in the current broadcast domain when sending the broadcast packet. The calculation method of the broadcast address is to negate the subnet mask and then perform or calculate with the broadcast domain.
For example, if the host belongs to a broadcast domain of 192.168.0.0 and the subnet mask is 255.255.0.0, the broadcast address is 192.168.255.255.
Use UDP for cross-network segment broadcasting
To enable the broadcast packet sent by host A to be received by host B on another network segment, it is only necessary to change the subnet mask of host A so that it is in the same broadcast domain as host B, and then use the broadcast address of the new broadcast domain to send the broadcast packet.
For example, if you want to use 192.168.23.150 to send a broadcast packet for 192.168.27.135 to receive, you only need to set the subnet mask of 192.168.23.150 to 255.255.0.0, and then use the broadcast address 192.168.255.255.
In particular, 255.255.255.255 is a restricted broadcast address and cannot be used to send broadcast packets.
https://www.cnblogs.com/caicaizi/p/7371937.html
|
|