2011-08-11 96 views

回答

4

/24表示構成地址網絡部分的比特數,在本例中爲24(或30)。

如果您與僅具有最小網絡部分的IP地址相同的網絡將包含相同的值。

舉例來說,這裏是一個C語言實現(未經測試):

unsigned int ip1 = (192<<24) | (168<<16) | (0<<8) | (1); 
unsigned int ip2 = (192<<24) | (168<<16) | (0<<8) | (2); 
unsigned int nm1 = (-1) << (32 - 24); 
ip1 &= nm1; // Note: we use nm1 as its the smallest number of bits in the network 
ip2 &= nm1; 
if (ip1 == ip2) { } // Same network 

從技術上講,你的/ 30/24 不同的網絡,並會使用路由器來達到不同的地址(即/ 24將不使用IP 1-254的路由器,而/ 30將使用大多數這些地址的路由器)。但是,它們在相同的地址空間中重疊。

+0

感謝您的回答,Ramin。你的意思是,如果(ip1&subnet1的結果)==(ip2&subnet2的結果),那麼無論subnet1 == subnet2,最終結果都是OK。我對嗎? – danspeed

相關問題