Product SiteDocumentation Site

7.3.4. Retrieving Detailed Interface Info

You may also find yourself with a virInterfacePtr, and need the name or MAC address of the interface, or want to examine the full interface configuration. virInterfaceGetName, virInterfaceGetMACString, and virInterfaceGetXMLDesc will take care of those needs.
const char *name;
const char *mac;

name = virInterfaceGetName(iface);
mac = virInterfaceGetMACString(iface);

printf("Interface %s has MAC address %s", name, mac);
Example 7.9. Fetching the name and mac address from an interface object

Note that the strings returned by virInterfaceGetName and virInterfaceGetMACString do not need to be freed by the application; their lifetime will be the same as the interface object.
The string returned by virInterfaceGetXMLDesc, on the other hand, is created especially for the caller, and the caller must free it when finished. virInterfacegetXMLDesc also has a flags argument, intended for future expansion. For forward compatibility, you should always set it to 0. The returned string is UTF-8 encoded; the same string may later be given to virInterfaceDefineXML to recreate the interface configuration.
const char *xml;

name = virInterfaceGetXMLDesc(iface, 0);
printf("Interface configuration:\n%s\n", xml);
free(xml);
Example 7.10. Fetching the XML configuration string from an interface object