Calculate broadcast address from ip and subnet mask

后端 未结 5 655
一向
一向 2020-12-09 04:17

I want to calculate the broadcast address for:

IP:     192.168.3.1
Subnet: 255.255.255.0
=       192.168.3.255

in C.

I know the way

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 05:14

    Just calculate:

    broadcast = ip | ( ~ subnet )
    

    (Broadcast = ip-addr or the inverted subnet-mask)

    The broadcast address has a 1 bit where the subnet mask has a 0 bit.

提交回复
热议问题