<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi all, </span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I am new to libvirt and started looking at the source code. While tracing back the virsh command "net-create", I got stuck into a loop and I would really like someone to explain how this works. </div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
In the virsh-network.c, from:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="courier new, monospace"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<font face="courier new, monospace">network = virNetworkCreateXML(ctl->conn, buffer); </font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br>
</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">I traced back to: </font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><div><font face="courier new, monospace">if (conn->networkDriver && conn->networkDriver->networkCreateXML) {</font></div>
<div><font face="courier new, monospace"> virNetworkPtr ret;</font></div><div><font face="courier new, monospace"> ret = conn->networkDriver->networkCreateXML(conn, xmlDesc);</font></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">Then I traced back to the following struct to find how networkCreateXML is working:</font></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div><font face="courier new, monospace">struct _virNetworkDriver {</font></div><div><font face="courier new, monospace"> const char * name; /* the name of the driver */</font></div><div><font face="courier new, monospace"> virDrvOpen open;</font></div>
<div><font face="courier new, monospace"> virDrvClose close;</font></div><div><font face="courier new, monospace"> virDrvNumOfNetworks numOfNetworks;</font></div><div><font face="courier new, monospace"> virDrvListNetworks listNetworks;</font></div>
<div><font face="courier new, monospace"> virDrvNumOfDefinedNetworks numOfDefinedNetworks;</font></div><div><font face="courier new, monospace"> virDrvListDefinedNetworks listDefinedNetworks;</font></div>
<div><font face="courier new, monospace"> virDrvListAllNetworks listAllNetworks;</font></div><div><font face="courier new, monospace"> virDrvNetworkLookupByUUID networkLookupByUUID;</font></div><div>
<font face="courier new, monospace"> virDrvNetworkLookupByName networkLookupByName;</font></div><div><font face="courier new, monospace"> virDrvNetworkCreateXML networkCreateXML;</font></div><div style="font-family:arial,helvetica,sans-serif">
<br></div><div><font face="arial, helvetica, sans-serif">From the above code, I located the definition of </font><span style="font-family:'courier new',monospace">virDrvNetworkCreateXML </span><font face="arial, helvetica, sans-serif">and found the following:</font></div>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div><font face="courier new, monospace">typedef virNetworkPtr</font></div><div><font face="courier new, monospace"> (*virDrvNetworkCreateXML) (virConnectPtr conn,</font></div><div><font face="courier new, monospace"> const char *xmlDesc);</font></div>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">This is where I am unable to trace back to any other code. Can someone please explain the code with typedef above and where is the definition of the function this function pointer is pointing to? I want to get to the root of the networkCreateXML function and how it exactly works. Can someone please explain? </font></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif"><br></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<font face="arial, helvetica, sans-serif">Thanks a lot,</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><font face="arial, helvetica, sans-serif">Bilal</font></div>