# Module libvirt-network from libvirt

Provides APIs for the management of networks Copyright (C) 2006-2014 Red Hat, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.

## Table of Contents

### Macros

    #define VIR_NETWORK_EVENT_CALLBACK
    #define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE
    #define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST
    #define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR
    #define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK
    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE
    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST
    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK

### Types

    typedef enum virConnectListAllNetworksFlags
    typedef enum virIPAddrType
    typedef struct _virNetwork virNetwork
    typedef struct _virNetworkDHCPLease virNetworkDHCPLease
    typedef virNetworkDHCPLease * virNetworkDHCPLeasePtr
    typedef enum virNetworkEventID
    typedef enum virNetworkEventLifecycleType
    typedef struct _virNetworkPort virNetworkPort
    typedef enum virNetworkPortCreateFlags
    typedef virNetworkPort * virNetworkPortPtr
    typedef virNetwork * virNetworkPtr
    typedef enum virNetworkUpdateCommand
    typedef enum virNetworkUpdateFlags
    typedef enum virNetworkUpdateSection
    typedef enum virNetworkXMLFlags

### Functions

    int	virConnectListAllNetworks	(virConnectPtr conn,
    					 virNetworkPtr ** nets,
    					 unsigned int flags)
    int	virConnectListDefinedNetworks	(virConnectPtr conn,
    					 char ** const names,
    					 int maxnames)
    int	virConnectListNetworks		(virConnectPtr conn,
    					 char ** const names,
    					 int maxnames)
    int	virConnectNetworkEventDeregisterAny	(virConnectPtr conn,
    						 int callbackID)
    typedef virConnectNetworkEventGenericCallback
    void	virConnectNetworkEventGenericCallback	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 void * opaque)

    typedef virConnectNetworkEventLifecycleCallback
    void	virConnectNetworkEventLifecycleCallback	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 int event,
    						 int detail,
    						 void * opaque)

    int	virConnectNetworkEventRegisterAny	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 int eventID,
    						 virConnectNetworkEventGenericCallback cb,
    						 void * opaque,
    						 virFreeCallback freecb)
    int	virConnectNumOfDefinedNetworks	(virConnectPtr conn)
    int	virConnectNumOfNetworks		(virConnectPtr conn)
    int	virNetworkCreate		(virNetworkPtr network)
    virNetworkPtr	virNetworkCreateXML	(virConnectPtr conn,
    					 const char * xmlDesc)
    void	virNetworkDHCPLeaseFree		(virNetworkDHCPLeasePtr lease)
    virNetworkPtr	virNetworkDefineXML	(virConnectPtr conn,
    					 const char * xml)
    int	virNetworkDestroy		(virNetworkPtr network)
    int	virNetworkFree			(virNetworkPtr network)
    int	virNetworkGetAutostart		(virNetworkPtr network,
    					 int * autostart)
    char *	virNetworkGetBridgeName		(virNetworkPtr network)
    virConnectPtr	virNetworkGetConnect	(virNetworkPtr net)
    int	virNetworkGetDHCPLeases		(virNetworkPtr network,
    					 const char * mac,
    					 virNetworkDHCPLeasePtr ** leases,
    					 unsigned int flags)
    const char *	virNetworkGetName	(virNetworkPtr network)
    int	virNetworkGetUUID		(virNetworkPtr network,
    					 unsigned char * uuid)
    int	virNetworkGetUUIDString		(virNetworkPtr network,
    					 char * buf)
    char *	virNetworkGetXMLDesc		(virNetworkPtr network,
    					 unsigned int flags)
    int	virNetworkIsActive		(virNetworkPtr net)
    int	virNetworkIsPersistent		(virNetworkPtr net)
    int	virNetworkListAllPorts		(virNetworkPtr network,
    					 virNetworkPortPtr ** ports,
    					 unsigned int flags)
    virNetworkPtr	virNetworkLookupByName	(virConnectPtr conn,
    					 const char * name)
    virNetworkPtr	virNetworkLookupByUUID	(virConnectPtr conn,
    					 const unsigned char * uuid)
    virNetworkPtr	virNetworkLookupByUUIDString	(virConnectPtr conn,
    						 const char * uuidstr)
    virNetworkPortPtr	virNetworkPortCreateXML	(virNetworkPtr net,
    						 const char * xmldesc,
    						 unsigned int flags)
    int	virNetworkPortDelete		(virNetworkPortPtr port,
    					 unsigned int flags)
    int	virNetworkPortFree		(virNetworkPortPtr port)
    virNetworkPtr	virNetworkPortGetNetwork	(virNetworkPortPtr port)
    int	virNetworkPortGetParameters	(virNetworkPortPtr port,
    					 virTypedParameterPtr * params,
    					 int * nparams,
    					 unsigned int flags)
    int	virNetworkPortGetUUID		(virNetworkPortPtr port,
    					 unsigned char * uuid)
    int	virNetworkPortGetUUIDString	(virNetworkPortPtr port,
    					 char * buf)
    char *	virNetworkPortGetXMLDesc	(virNetworkPortPtr port,
    					 unsigned int flags)
    virNetworkPortPtr	virNetworkPortLookupByUUID	(virNetworkPtr net,
    							 const unsigned char * uuid)
    virNetworkPortPtr	virNetworkPortLookupByUUIDString	(virNetworkPtr net,
    							 const char * uuidstr)
    int	virNetworkPortRef		(virNetworkPortPtr port)
    int	virNetworkPortSetParameters	(virNetworkPortPtr port,
    					 virTypedParameterPtr params,
    					 int nparams,
    					 unsigned int flags)
    int	virNetworkRef			(virNetworkPtr network)
    int	virNetworkSetAutostart		(virNetworkPtr network,
    					 int autostart)
    int	virNetworkUndefine		(virNetworkPtr network)
    int	virNetworkUpdate		(virNetworkPtr network,
    					 unsigned int command,
    					 unsigned int section,
    					 int parentIndex,
    					 const char * xml,
    					 unsigned int flags)

## Description

### Macros

### `VIR_NETWORK_EVENT_CALLBACK`

    #define VIR_NETWORK_EVENT_CALLBACK

Used to cast the event specific callback into the generic one for use for virConnectNetworkEventRegisterAny()

### `VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE`

    #define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE

Macro represents the inbound average of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_IN_BURST`

    #define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST

Macro represents the inbound burst of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR`

    #define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR

Macro represents the inbound floor of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK`

    #define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK

Macro represents the inbound peak of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE`

    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE

Macro represents the outbound average of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST`

    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST

Macro represents the outbound burst of NIC bandwidth, as a uint.

### `VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK`

    #define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK

Macro represents the outbound peak of NIC bandwidth, as a uint.

### Types

### `virConnectListAllNetworksFlags`

    enum virConnectListAllNetworksFlags {

VIR_CONNECT_LIST_NETWORKS_INACTIVE | = | 1 (0x1; 1 << 0)
VIR_CONNECT_LIST_NETWORKS_ACTIVE | = | 2 (0x2; 1 << 1)
VIR_CONNECT_LIST_NETWORKS_PERSISTENT | = | 4 (0x4; 1 << 2)
VIR_CONNECT_LIST_NETWORKS_TRANSIENT | = | 8 (0x8; 1 << 3)
VIR_CONNECT_LIST_NETWORKS_AUTOSTART | = | 16 (0x10; 1 << 4)
VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART | = | 32 (0x20; 1 << 5)

    }

### `virIPAddrType`

    enum virIPAddrType {

VIR_IP_ADDR_TYPE_IPV4 | = | 0 (0x0)
VIR_IP_ADDR_TYPE_IPV6 | = | 1 (0x1)
VIR_IP_ADDR_TYPE_LAST | = | 2 (0x2)

    }

### `virNetwork`

    struct virNetwork {

The content of this structure is not made public by the API

    }

### `virNetworkDHCPLease`

    struct virNetworkDHCPLease {

char * | iface | Network interface name
long long | expirytime | Seconds since epoch
int | type | virIPAddrType
char * | mac | MAC address
char * | iaid | IAID
char * | ipaddr | IP address
unsigned int | prefix | IP address prefix
char * | hostname | Hostname
char * | clientid | Client ID or DUID

    }

### `virNetworkEventID`

    enum virNetworkEventID {

VIR_NETWORK_EVENT_ID_LIFECYCLE | = | 0 (0x0) | virConnectNetworkEventLifecycleCallback
VIR_NETWORK_EVENT_ID_LAST | = | 1 (0x1) | NB: this enum value will increase over time as new events are added to the libvirt API. It reflects the last event ID supported by this version of the libvirt API.

    }

### `virNetworkEventLifecycleType`

    enum virNetworkEventLifecycleType {

VIR_NETWORK_EVENT_DEFINED | = | 0 (0x0)
VIR_NETWORK_EVENT_UNDEFINED | = | 1 (0x1)
VIR_NETWORK_EVENT_STARTED | = | 2 (0x2)
VIR_NETWORK_EVENT_STOPPED | = | 3 (0x3)
VIR_NETWORK_EVENT_LAST | = | 4 (0x4)

    }

### `virNetworkPort`

    struct virNetworkPort {

The content of this structure is not made public by the API

    }

### `virNetworkPortCreateFlags`

    enum virNetworkPortCreateFlags {

VIR_NETWORK_PORT_CREATE_RECLAIM | = | 1 (0x1; 1 << 0) | reclaim existing used resources

    }

### `virNetworkUpdateCommand`

    enum virNetworkUpdateCommand {

VIR_NETWORK_UPDATE_COMMAND_NONE | = | 0 (0x0) | (invalid)
VIR_NETWORK_UPDATE_COMMAND_MODIFY | = | 1 (0x1) | modify an existing element
VIR_NETWORK_UPDATE_COMMAND_DELETE | = | 2 (0x2) | delete an existing element
VIR_NETWORK_UPDATE_COMMAND_ADD_LAST | = | 3 (0x3) | add an element at end of list
VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST | = | 4 (0x4) | add an element at start of list
VIR_NETWORK_UPDATE_COMMAND_LAST | = | 5 (0x5)

    }

### `virNetworkUpdateFlags`

    enum virNetworkUpdateFlags {

VIR_NETWORK_UPDATE_AFFECT_CURRENT | = | 0 (0x0) | affect live if network is active, config if it's not active
VIR_NETWORK_UPDATE_AFFECT_LIVE | = | 1 (0x1; 1 << 0) | affect live state of network only
VIR_NETWORK_UPDATE_AFFECT_CONFIG | = | 2 (0x2; 1 << 1) | affect persistent config only

    }

### `virNetworkUpdateSection`

    enum virNetworkUpdateSection {

VIR_NETWORK_SECTION_NONE | = | 0 (0x0) | (invalid)
VIR_NETWORK_SECTION_BRIDGE | = | 1 (0x1) | <bridge>
VIR_NETWORK_SECTION_DOMAIN | = | 2 (0x2) | <domain>
VIR_NETWORK_SECTION_IP | = | 3 (0x3) | <ip>
VIR_NETWORK_SECTION_IP_DHCP_HOST | = | 4 (0x4) | <ip>/<dhcp>/<host>
VIR_NETWORK_SECTION_IP_DHCP_RANGE | = | 5 (0x5) | <ip>/<dhcp>/<range>
VIR_NETWORK_SECTION_FORWARD | = | 6 (0x6) | <forward>
VIR_NETWORK_SECTION_FORWARD_INTERFACE | = | 7 (0x7) | <forward>/<interface>
VIR_NETWORK_SECTION_FORWARD_PF | = | 8 (0x8) | <forward>/<pf>
VIR_NETWORK_SECTION_PORTGROUP | = | 9 (0x9) | <portgroup>
VIR_NETWORK_SECTION_DNS_HOST | = | 10 (0xa) | <dns>/<host>
VIR_NETWORK_SECTION_DNS_TXT | = | 11 (0xb) | <dns>/<txt>
VIR_NETWORK_SECTION_DNS_SRV | = | 12 (0xc) | <dns>/<srv>
VIR_NETWORK_SECTION_LAST | = | 13 (0xd)

    }

### `virNetworkXMLFlags`

    enum virNetworkXMLFlags {

VIR_NETWORK_XML_INACTIVE | = | 1 (0x1; 1 << 0) | dump inactive network information

    }

### Functions

### `virConnectListAllNetworks`

    int	virConnectListAllNetworks	(virConnectPtr conn,
    					 virNetworkPtr ** nets,
    					 unsigned int flags)

Collect the list of networks, and allocate an array to store those objects. This API solves the race inherent between virConnectListNetworks and virConnectListDefinedNetworks.

Normally, all networks are returned; however, @flags can be used to filter the results for a smaller list of targeted networks. The valid flags are divided into groups, where each group contains bits that describe mutually exclusive attributes of a network, and where all bits within a group describe all possible networks.

The first group of @flags is VIR_CONNECT_LIST_NETWORKS_ACTIVE (up) and VIR_CONNECT_LIST_NETWORKS_INACTIVE (down) to filter the networks by state.

The second group of @flags is VIR_CONNECT_LIST_NETWORKS_PERSISTENT (defined) and VIR_CONNECT_LIST_NETWORKS_TRANSIENT (running but not defined), to filter the networks by whether they have persistent config or not.

The third group of @flags is VIR_CONNECT_LIST_NETWORKS_AUTOSTART and VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART, to filter the networks by whether they are marked as autostart or not.

conn
  Pointer to the hypervisor connection.
nets
  Pointer to a variable to store the array containing the network objects or NULL if the list is not required (just returns number of networks).
flags
  bitwise-OR of virConnectListAllNetworksFlags.
Returns
  the number of networks found or -1 and sets @nets to NULL in case of error. On success, the array stored into @nets is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkFree() on each array element, then calling free() on @nets.

### `virConnectListDefinedNetworks`

    int	virConnectListDefinedNetworks	(virConnectPtr conn,
    					 char ** const names,
    					 int maxnames)

list the inactive networks, stores the pointers to the names in @names

For more control over the results, see virConnectListAllNetworks().

conn
  pointer to the hypervisor connection
names
  pointer to an array to store the names
maxnames
  size of the array
Returns
  the number of names provided in the array or -1 in case of error. Note that this command is inherently racy; a network can be defined between a call to virConnectNumOfDefinedNetworks() and this call; you are only guaranteed that all currently defined networks were listed if the return is less than @maxnames. The client must call free() on each returned name.

### `virConnectListNetworks`

    int	virConnectListNetworks		(virConnectPtr conn,
    					 char ** const names,
    					 int maxnames)

Collect the list of active networks, and store their names in @names

For more control over the results, see virConnectListAllNetworks().

conn
  pointer to the hypervisor connection
names
  array to collect the list of names of active networks
maxnames
  size of @names
Returns
  the number of networks found or -1 in case of error. Note that this command is inherently racy; a network can be started between a call to virConnectNumOfNetworks() and this call; you are only guaranteed that all currently active networks were listed if the return is less than @maxnames. The client must call free() on each returned name.

### `virConnectNetworkEventDeregisterAny`

    int	virConnectNetworkEventDeregisterAny	(virConnectPtr conn,
    						 int callbackID)

Removes an event callback. The callbackID parameter should be the value obtained from a previous virConnectNetworkEventRegisterAny() method.

conn
  pointer to the connection
callbackID
  the callback identifier
Returns
  0 on success, -1 on failure

### `virConnectNetworkEventGenericCallback`

    typedef void	(*virConnectNetworkEventGenericCallback)	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 void * opaque)

A generic network event callback handler, for use with virConnectNetworkEventRegisterAny(). Specific events usually have a customization with extra parameters, often with @opaque being passed in a different parameter position; use VIR_NETWORK_EVENT_CALLBACK() when registering an appropriate handler.

conn
  the connection pointer
net
  the network pointer
opaque
  application specified data

### `virConnectNetworkEventLifecycleCallback`

    typedef void	(*virConnectNetworkEventLifecycleCallback)	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 int event,
    						 int detail,
    						 void * opaque)

This callback occurs when the network is started or stopped.

The callback signature to use when registering for an event of type VIR_NETWORK_EVENT_ID_LIFECYCLE with virConnectNetworkEventRegisterAny()

conn
  connection object
net
  network on which the event occurred
event
  The specific virNetworkEventLifeCycleType which occurred
detail
  contains some details on the reason of the event. It will be 0 for the while.
opaque
  application specified data

### `virConnectNetworkEventRegisterAny`

    int	virConnectNetworkEventRegisterAny	(virConnectPtr conn,
    						 virNetworkPtr net,
    						 int eventID,
    						 virConnectNetworkEventGenericCallback cb,
    						 void * opaque,
    						 virFreeCallback freecb)

Adds a callback to receive notifications of arbitrary network events occurring on a network. This function requires that an event loop has been previously registered with virEventRegisterImpl() or virEventRegisterDefaultImpl().

If @net is NULL, then events will be monitored for any network. If @net is non-NULL, then only the specific network will be monitored.

Most types of event have a callback providing a custom set of parameters for the event. When registering an event, it is thus necessary to use the VIR_NETWORK_EVENT_CALLBACK() macro to cast the supplied function pointer to match the signature of this method.

The virNetworkPtr object handle passed into the callback upon delivery of an event is only valid for the duration of execution of the callback. If the callback wishes to keep the network object after the callback returns, it shall take a reference to it, by calling virNetworkRef(). The reference can be released once the object is no longer required by calling virNetworkFree().

The return value from this method is a positive integer identifier for the callback. To unregister a callback, this callback ID should be passed to the virConnectNetworkEventDeregisterAny() method.

conn
  pointer to the connection
net
  pointer to the network
eventID
  the event type to receive
cb
  callback to the function handling network events
opaque
  opaque data to pass on to the callback
freecb
  optional function to deallocate opaque when not used anymore
Returns
  a callback identifier on success, -1 on failure.

### `virConnectNumOfDefinedNetworks`

    int	virConnectNumOfDefinedNetworks	(virConnectPtr conn)

Provides the number of inactive networks.

conn
  pointer to the hypervisor connection
Returns
  the number of networks found or -1 in case of error

### `virConnectNumOfNetworks`

    int	virConnectNumOfNetworks		(virConnectPtr conn)

Provides the number of active networks.

conn
  pointer to the hypervisor connection
Returns
  the number of network found or -1 in case of error

### `virNetworkCreate`

    int	virNetworkCreate		(virNetworkPtr network)

Create and start a defined network. If the call succeed the network moves from the defined to the running networks pools.

network
  pointer to a defined network
Returns
  0 in case of success, -1 in case of error

### `virNetworkCreateXML`

    virNetworkPtr	virNetworkCreateXML	(virConnectPtr conn,
    					 const char * xmlDesc)

Create and start a new virtual network, based on an XML description similar to the one returned by virNetworkGetXMLDesc()

virNetworkFree should be used to free the resources after the network object is no longer needed.

conn
  pointer to the hypervisor connection
xmlDesc
  an XML description of the network
Returns
  a new network object or NULL in case of failure

### `virNetworkDHCPLeaseFree`

    void	virNetworkDHCPLeaseFree		(virNetworkDHCPLeasePtr lease)

Frees all the memory occupied by @lease.

lease
  pointer to a leases object

### `virNetworkDefineXML`

    virNetworkPtr	virNetworkDefineXML	(virConnectPtr conn,
    					 const char * xml)

Define an inactive persistent virtual network or modify an existing persistent one from the XML description.

virNetworkFree should be used to free the resources after the network object is no longer needed.

conn
  pointer to the hypervisor connection
xml
  the XML description for the network, preferably in UTF-8
Returns
  NULL in case of error, a pointer to the network otherwise

### `virNetworkDestroy`

    int	virNetworkDestroy		(virNetworkPtr network)

Destroy the network object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. This does not free the associated virNetworkPtr object. This function may require privileged access

network
  a network object
Returns
  0 in case of success and -1 in case of failure.

### `virNetworkFree`

    int	virNetworkFree			(virNetworkPtr network)

Free the network object. The running instance is kept alive. The data structure is freed and should not be used thereafter.

network
  a network object
Returns
  0 in case of success and -1 in case of failure.

### `virNetworkGetAutostart`

    int	virNetworkGetAutostart		(virNetworkPtr network,
    					 int * autostart)

Provides a boolean value indicating whether the network configured to be automatically started when the host machine boots.

network
  a network object
autostart
  the value returned
Returns
  -1 in case of error, 0 in case of success

### `virNetworkGetBridgeName`

    char *	virNetworkGetBridgeName		(virNetworkPtr network)

Provides a bridge interface name to which a domain may connect a network interface in order to join the network.

network
  a network object
Returns
  a 0 terminated interface name, or NULL in case of error. The caller must free() the returned value.

### `virNetworkGetConnect`

    virConnectPtr	virNetworkGetConnect	(virNetworkPtr net)

Provides the connection pointer associated with a network. The reference counter on the connection is not increased by this call.

net
  pointer to a network
Returns
  the virConnectPtr or NULL in case of failure.

### `virNetworkGetDHCPLeases`

    int	virNetworkGetDHCPLeases		(virNetworkPtr network,
    					 const char * mac,
    					 virNetworkDHCPLeasePtr ** leases,
    					 unsigned int flags)

For DHCPv4, the information returned: - Network Interface Name - Expiry Time - MAC address - IAID (NULL) - IPv4 address (with type and prefix) - Hostname (can be NULL) - Client ID (can be NULL)

For DHCPv6, the information returned: - Network Interface Name - Expiry Time - MAC address - IAID (can be NULL, only in rare cases) - IPv6 address (with type and prefix) - Hostname (can be NULL) - Client DUID

Note: @mac, @iaid, @ipaddr, @clientid are in ASCII form, not raw bytes. Note: @expirytime can 0, in case the lease is for infinite time.

The API fetches leases info of guests in the specified network. If the optional parameter @mac is specified, the returned list will contain only lease info about a specific guest interface with @mac. There can be multiple leases for a single @mac because this API supports DHCPv6 too.

On success, the array stored into @leases is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkDHCPLeaseFree() on each array element, then calling free() on @leases.

See also virNetworkGetDHCPLeasesForMAC() as a convenience for filtering the list to a single MAC address.

Example of usage:

    virNetworkDHCPLeasePtr *leases = NULL;
    virNetworkPtr network = ... obtain a network pointer here ...;
    size_t i;
    int nleases;
    unsigned int flags = 0;

    nleases = virNetworkGetDHCPLeases(network, NULL, &leases, flags);
    if (nleases < 0)
        error();

    ... do something with returned values, for example:

    for (i = 0; i < nleases; i++) {
        virNetworkDHCPLeasePtr lease = leases[i];

        printf("Time(epoch): %lu, MAC address: %s, "
               "IP address: %s, Hostname: %s, ClientID: %s\n",
               lease->expirytime, lease->mac, lease->ipaddr,
               lease->hostname, lease->clientid);

               virNetworkDHCPLeaseFree(leases[i]);
    }

    free(leases);

network
  Pointer to network object
mac
  Optional ASCII formatted MAC address of an interface
leases
  Pointer to a variable to store the array containing details on obtained leases, or NULL if the list is not required (just returns number of leases).
flags
  Extra flags, not used yet, so callers should always pass 0
Returns
  the number of leases found or -1 and sets @leases to NULL in case of error.

### `virNetworkGetName`

    const char *	virNetworkGetName	(virNetworkPtr network)

Get the public name for that network

network
  a network object
Returns
  a pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the network object.

### `virNetworkGetUUID`

    int	virNetworkGetUUID		(virNetworkPtr network,
    					 unsigned char * uuid)

Get the UUID for a network

network
  a network object
uuid
  pointer to a VIR_UUID_BUFLEN bytes array
Returns
  -1 in case of error, 0 in case of success

### `virNetworkGetUUIDString`

    int	virNetworkGetUUIDString		(virNetworkPtr network,
    					 char * buf)

Get the UUID for a network as string. For more information about UUID see RFC4122.

network
  a network object
buf
  pointer to a VIR_UUID_STRING_BUFLEN bytes array
Returns
  -1 in case of error, 0 in case of success

### `virNetworkGetXMLDesc`

    char *	virNetworkGetXMLDesc		(virNetworkPtr network,
    					 unsigned int flags)

Provide an XML description of the network. The description may be reused later to relaunch the network with virNetworkCreateXML().

Normally, if a network included a physical function, the output includes all virtual functions tied to that physical interface. If @flags includes VIR_NETWORK_XML_INACTIVE, then the expansion of virtual interfaces is not performed.

network
  a network object
flags
  bitwise-OR of virNetworkXMLFlags
Returns
  a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. The caller must free() the returned value.

### `virNetworkIsActive`

    int	virNetworkIsActive		(virNetworkPtr net)

Determine if the network is currently running

net
  pointer to the network object
Returns
  1 if running, 0 if inactive, -1 on error

### `virNetworkIsPersistent`

    int	virNetworkIsPersistent		(virNetworkPtr net)

Determine if the network has a persistent configuration which means it will still exist after shutting down

net
  pointer to the network object
Returns
  1 if persistent, 0 if transient, -1 on error

### `virNetworkListAllPorts`

    int	virNetworkListAllPorts		(virNetworkPtr network,
    					 virNetworkPortPtr ** ports,
    					 unsigned int flags)

Collect the list of network ports, and allocate an array to store those objects.

network
  pointer to a network object
ports
  Pointer to a variable to store the array containing network port objects or NULL if the list is not required (just returns number of ports).
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  the number of network ports found or -1 and sets @ports to NULL in case of error. On success, the array stored into @ports is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkPortFree() on each array element, then calling free() on @ports.

### `virNetworkLookupByName`

    virNetworkPtr	virNetworkLookupByName	(virConnectPtr conn,
    					 const char * name)

Try to lookup a network on the given hypervisor based on its name.

virNetworkFree should be used to free the resources after the network object is no longer needed.

conn
  pointer to the hypervisor connection
name
  name for the network
Returns
  a new network object or NULL in case of failure. If the network cannot be found, then VIR_ERR_NO_NETWORK error is raised.

### `virNetworkLookupByUUID`

    virNetworkPtr	virNetworkLookupByUUID	(virConnectPtr conn,
    					 const unsigned char * uuid)

Try to lookup a network on the given hypervisor based on its UUID.

virNetworkFree should be used to free the resources after the network object is no longer needed.

conn
  pointer to the hypervisor connection
uuid
  the raw UUID for the network
Returns
  a new network object or NULL in case of failure. If the network cannot be found, then VIR_ERR_NO_NETWORK error is raised.

### `virNetworkLookupByUUIDString`

    virNetworkPtr	virNetworkLookupByUUIDString	(virConnectPtr conn,
    						 const char * uuidstr)

Try to lookup a network on the given hypervisor based on its UUID.

conn
  pointer to the hypervisor connection
uuidstr
  the string UUID for the network
Returns
  a new network object or NULL in case of failure. If the network cannot be found, then VIR_ERR_NO_NETWORK error is raised.

### `virNetworkPortCreateXML`

    virNetworkPortPtr	virNetworkPortCreateXML	(virNetworkPtr net,
    						 const char * xmldesc,
    						 unsigned int flags)

Create a new network port, based on an XML description similar to the one returned by virNetworkPortGetXMLDesc()

virNetworkPortFree should be used to free the resources after the network port object is no longer needed.

net
  pointer to the network object
xmldesc
  an XML description of the port
flags
  currently unused, pass 0
Returns
  a new network port object or NULL in case of failure

### `virNetworkPortDelete`

    int	virNetworkPortDelete		(virNetworkPortPtr port,
    					 unsigned int flags)

Delete the network port. This does not free the associated virNetworkPortPtr object. It is the caller's responsibility to ensure the port is not still in use by a virtual machine before deleting port.

port
  a port object
flags
  currently unused, pass 0
Returns
  0 in case of success and -1 in case of failure.

### `virNetworkPortFree`

    int	virNetworkPortFree		(virNetworkPortPtr port)

Free the network port object. The data structure is freed and should not be used thereafter.

port
  a network port object
Returns
  0 in case of success and -1 in case of failure.

### `virNetworkPortGetNetwork`

    virNetworkPtr	virNetworkPortGetNetwork	(virNetworkPortPtr port)

Provides the network pointer associated with a port. The reference counter on the connection is not increased by this call.

port
  pointer to a network port
Returns
  the virNetworkPtr or NULL in case of failure.

### `virNetworkPortGetParameters`

    int	virNetworkPortGetParameters	(virNetworkPortPtr port,
    					 virTypedParameterPtr * params,
    					 int * nparams,
    					 unsigned int flags)

Get all interface parameters. On input, @params should be initialized to NULL. On return @params will be allocated with the size large enough to hold all parameters, and @nparams will be updated to say how many parameters are present. @params should be freed by the caller on success.

port
  a network port object
params
  pointer to pointer of interface parameter objects
nparams
  pointer to received number of interface parameter
flags
  currently unused, pass 0
Returns
  -1 in case of error, 0 in case of success.

### `virNetworkPortGetUUID`

    int	virNetworkPortGetUUID		(virNetworkPortPtr port,
    					 unsigned char * uuid)

Get the UUID for a network port

port
  a network port object
uuid
  pointer to a VIR_UUID_BUFLEN bytes array
Returns
  -1 in case of error, 0 in case of success

### `virNetworkPortGetUUIDString`

    int	virNetworkPortGetUUIDString	(virNetworkPortPtr port,
    					 char * buf)

Get the UUID for a network as string. For more information about UUID see RFC4122.

port
  a network port object
buf
  pointer to a VIR_UUID_STRING_BUFLEN bytes array
Returns
  -1 in case of error, 0 in case of success

### `virNetworkPortGetXMLDesc`

    char *	virNetworkPortGetXMLDesc	(virNetworkPortPtr port,
    					 unsigned int flags)

Provide an XML description of the network port. The description may be reused later to recreate the port with virNetworkPortCreateXML().

port
  a network port object
flags
  currently unused, pass 0
Returns
  a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value.

### `virNetworkPortLookupByUUID`

    virNetworkPortPtr	virNetworkPortLookupByUUID	(virNetworkPtr net,
    							 const unsigned char * uuid)

Try to lookup a port on the given network based on its UUID.

virNetworkPortFree should be used to free the resources after the network port object is no longer needed.

net
  pointer to the network object
uuid
  the raw UUID for the network port
Returns
  a new network port object or NULL in case of failure. If the network port cannot be found, then VIR_ERR_NO_NETWORK_PORT error is raised.

### `virNetworkPortLookupByUUIDString`

    virNetworkPortPtr	virNetworkPortLookupByUUIDString	(virNetworkPtr net,
    							 const char * uuidstr)

Try to lookup a port on the given network based on its UUID.

net
  pointer to the network object
uuidstr
  the string UUID for the port
Returns
  a new network port object or NULL in case of failure. If the network port cannot be found, then VIR_ERR_NO_NETWORK_PORT error is raised.

### `virNetworkPortRef`

    int	virNetworkPortRef		(virNetworkPortPtr port)

Increment the reference count on the network port. For each additional call to this method, there shall be a corresponding call to virNetworkPortFree to release the reference count, once the caller no longer needs the reference to this object.

This method is typically useful for applications where multiple threads are using a network port, and it is required that the port remain resident until all threads have finished using it. ie, each new thread using a network port would increment the reference count.

port
  a network port object
Returns
  0 in case of success, -1 in case of failure.

### `virNetworkPortSetParameters`

    int	virNetworkPortSetParameters	(virNetworkPortPtr port,
    					 virTypedParameterPtr params,
    					 int nparams,
    					 unsigned int flags)

Change a subset or all parameters of the network port; currently this includes bandwidth parameters.

port
  a network port object
params
  pointer to interface parameter objects
nparams
  number of interface parameter (this value can be the same or less than the number of parameters supported)
flags
  currently unused, pass 0
Returns
  -1 in case of error, 0 in case of success.

### `virNetworkRef`

    int	virNetworkRef			(virNetworkPtr network)

Increment the reference count on the network. For each additional call to this method, there shall be a corresponding call to virNetworkFree to release the reference count, once the caller no longer needs the reference to this object.

This method is typically useful for applications where multiple threads are using a connection, and it is required that the connection remain open until all threads have finished using it. ie, each new thread using a network would increment the reference count.

network
  the network to hold a reference on
Returns
  0 in case of success, -1 in case of failure.

### `virNetworkSetAutostart`

    int	virNetworkSetAutostart		(virNetworkPtr network,
    					 int autostart)

Configure the network to be automatically started when the host machine boots.

network
  a network object
autostart
  whether the network should be automatically started 0 or 1
Returns
  -1 in case of error, 0 in case of success

### `virNetworkUndefine`

    int	virNetworkUndefine		(virNetworkPtr network)

Undefine a network but does not stop it if it is running

network
  pointer to a defined network
Returns
  0 in case of success, -1 in case of error

### `virNetworkUpdate`

    int	virNetworkUpdate		(virNetworkPtr network,
    					 unsigned int command,
    					 unsigned int section,
    					 int parentIndex,
    					 const char * xml,
    					 unsigned int flags)

Update the definition of an existing network, either its live running state, its persistent configuration, or both.

network
  pointer to a defined network
command
  what action to perform (add/delete/modify) (see virNetworkUpdateCommand for descriptions)
section
  which section of the network to update (see virNetworkUpdateSection for descriptions)
parentIndex
  which parent element, if there are multiple parents of the same type (e.g. which <ip> element when modifying a <dhcp>/<host> element), or "-1" for "don't care" or "automatically find appropriate one".
xml
  the XML description for the network, preferably in UTF-8
flags
  bitwise OR of virNetworkUpdateFlags.
Returns
  0 in case of success, -1 in case of error virNetworkUpdateCommand virNetworkUpdateSection