예제 #1
0
파일: utils.go 프로젝트: jojimt/netplugin
// getLocalAddr gets local address to be used
func getLocalAddr() (string, error) {
	// get the ip address by local hostname
	localIP, err := netutils.GetMyAddr()
	if err == nil && netutils.IsAddrLocal(localIP) {
		return localIP, nil
	}

	// Return first available address if we could not find by hostname
	return netutils.GetFirstLocalAddr()
}
예제 #2
0
// GetLocalAddr gets local address to be used
func GetLocalAddr() (string, error) {
	// Get objdb's client IP
	clientIP, err := client.NewClient().GetLocalAddr()
	if err != nil {
		log.Warnf("Error getting local address from objdb. Returning first local address. Err: %v", err)

		return netutils.GetFirstLocalAddr()
	}

	// Make sure the ip address is local
	if netutils.IsAddrLocal(clientIP) {
		return clientIP, nil
	}

	// Return first available address if client IP is not local
	return netutils.GetFirstLocalAddr()
}