Skip to content

Commit

Permalink
interface: Introduce a method to set the name.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
richardcochran committed Mar 4, 2020
1 parent a8df585 commit 47982fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ const char *interface_name(struct interface *iface)
{
return iface->name;
}

void interface_set_name(struct interface *iface, const char *name)
{
strncpy(iface->name, name, MAX_IFNAME_SIZE);
}
8 changes: 7 additions & 1 deletion interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ const char *interface_label(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

0 comments on commit 47982fb

Please sign in to comment.