Calculate broadcast address from ip and subnet mask

后端 未结 5 661
一向
一向 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 04:58

    Could it be?

    unsigned broadcast(unsigned ip,unsigned subnet){
        unsigned int bits = subnet ^ 0xffffffff; 
        unsigned int bcast = ip | bits;
    
        return bcast;
    }
    

    Edit: I considered that both ip and subnet are without "."

提交回复
热议问题