On 07/14/2011 05:42 PM, Matthias Bolte wrote: > 2011/7/14 Michal Novotny <minovotn@xxxxxxxxxx>: >> Hi guys, >> some time ago I've been investigating the options to get the guest's IP >> address information without having to connect to guest's VNC window or >> console. It was for one project I've been working on and I found that >> the solution lies in the procfs, precisely in the /proc/{PID}/net/arp... >> >> The format is as follows: >> >> $ cat /proc/{PID}/net/arp >> IP address HW type Flags HW address Mask >> Device >> 192.168.122.36 0x1 0x2 52:54:00:35:76:e6 * >> virbr0 >> >> where the HW address matches the MAC address associated to the guest's >> NIC. Implementing such an API shouldn't be a big problem however I know >> that there's some option to run libvirt on Windows machines. It should >> be just the client so it shouldn't really matter however I'd like to ask >> you whether it's really not an issue. > Windows or not is irrelevant here as the IP address lookup cannot be > implemented in a general way/place, but will have to be implemented by > the hypervisor/network drivers. > >> The function should return a string of the guest's IP address as read >> from the procfs or return a NULL value if there's no IP address >> associated with the guest. >> >> If the multiple NICs are being used by the guest then the function >> should return either the IP address matching the MAC address passed to >> the function or the first IP address if omitted. >> >> The prototype should be: >> >> char *virDomainGetIPAddress(virDomainPtr domain, char *devmac); > First of all you're missing the unsigned int flags parameter. > > Also did you consider that the MAC to IP(v4|v6) mapping isn't > necessarily a 1:1 mapping, but the signature of your function requires > this? Well, for this I considered the IPv4 address only. > I took a look at this and wonder what's the difference between > /proc/{PID}/net/arp and /proc/net/arp. Also as it's ARP it'll only > work for IPv4. Honestly I was unable to see it in /proc/net/arp. I saw just some ARP records but not related to the qemu-kvm process I tried on my Fedora-14 box but I was able to see those records in /proc/{PID}/net/arp and therefore I was looking to the /proc/{PID}/net/arp and why I mentioned this instead. Considering the fact this will be working just for IPv4 there should be some prototype like: char *virDomainGetIPAddress(virDomainPtr domain, char *devmac, unsigned int flags); where flags could be having either VIR_DOMAIN_ADDRESS_IPV4 or VIR_DOMAIN_ADDRESS_IPV6 with default to IPv4 address (if flags = 0). The option to get IPv4 address could be implemented the way like I mentioned and the IPv6 implementation could be deferred stating it's not supported yet if we don't know how to get such information. Personally I don't use IPv6 at all so I can't test it however having such option for IPv4 at least (which is widely used by most of the users AFAIK) could be a great thing. I think implementing it for IPv4 and then extending for IPv6 later should be the best thing we could do about this since many people would welcome the option to get the IP address using the libvirt API/virsh command with no need to connect to guest's VNC window/console and since most of them are using the IPv4 networking it would be good start with extending functionality to get IPv6 address later. Thanks, Michal -- Michal Novotny <minovotn@xxxxxxxxxx>, RHCE, Red Hat Virtualization | libvirt-php bindings | php-virt-control.org -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list