interface: Introduce a method to set the name.

The name field of the interface is set in different ways by different
callers.  In order to prevent users from open coding the logic that sets
the name, this patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
master
Richard Cochran 2020-02-09 13:26:24 -08:00
parent a8df585e04
commit 47982fb8c8
2 changed files with 12 additions and 1 deletions

View File

@ -27,3 +27,8 @@ const char *interface_name(struct interface *iface)
{ {
return iface->name; return iface->name;
} }
void interface_set_name(struct interface *iface, const char *name)
{
strncpy(iface->name, name, MAX_IFNAME_SIZE);
}

View File

@ -53,5 +53,11 @@ const char *interface_label(struct interface *iface);
*/ */
const char *interface_name(struct interface *iface); const char *interface_name(struct interface *iface);
#endif /**
* Set the name of a given interface.
* @param iface The interface of interest.
* @param name The desired name for the interface.
*/
void interface_set_name(struct interface *iface, const char *name);
#endif