Re: Host IP Address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 23, 2010 at 09:23:36AM +0200, Maximilian Wilhelm wrote:
> Anno domini 2010 IKI-サガル バルウェ scripsit:
> 
> Hi!
> 
> > Thanks for such a quick reply.
> 
> No problem :)
> 
> >> Did I get you right, that you have a 'virDomainPtr' as basis and want a
> >> mapping
> >> from that to the IP?
> > Yes. Thats what I want to do.
> 
> >> I guess one way could be to get the virConnectionPtr
> >>  conn_ptr = virDomainGetConnect (domain_ptr);
> 
> >> And then query the hostname
> >>  virConnectGetHostname (conn_ptr);
> >> or the uri
> >>  virConnectGetURI (conn_ptr);
> 
> >> and resolve the hostname or extract the IP/host from the URI and
> >> resolve that.
> 
> > Yes, I thought of this too. But I was hoping that the LibvirtAPI has some
> > way of giving me the host IP Address directly, instead of resolving it
> > myself.
> 
> I don't know of any and I wouldn't know which IP to choose if there
> were multiple.
> 
> > But then again, how would I resolve the IP Address from the hostname? Can
> > you please guide me on this.
> 
> In short:
> 
> struct hostent *hostent;
> hostent = gethostbyname (char *hostname);
> if (hostent) {
>         for (i = 0; hostent->h_addr_list[i]; i++)
> 		printf ("%s, ", hostent->h_addr_list[i]);
> 	printf ("\n");
> }

Never use gethostbyname in any new code. It is long since obsolete, not
thread safe and is hardcoded to only work with IPv4.

There is a good exmaple of how to use the modern replacemenbt, getaddrinfo(),
to resolve hostnames here:

 http://people.redhat.com/drepper/userapi-ipv6.html

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]