2016-03-22 68 views

回答

0

鏈接@Dsafds有答案。這裏爲了歷史的緣故,所以你不必自己閱讀線索。代碼是Mikio Hara的,由我做了一些小修改。

func lastAddr(n *net.IPNet) (net.IP, error) { // works when the n is a prefix, otherwise... 
    if n.IP.To4() == nil { 
     return net.IP{}, errors.New("does not support IPv6 addresses.") 
    } 
    ip := make(net.IP, len(n.IP.To4())) 
    binary.BigEndian.PutUint32(ip, binary.BigEndian.Uint32(n.IP.To4())|^binary.BigEndian.Uint32(net.IP(n.Mask).To4())) 
    return ip, nil 
}