From 47982fb8c8c2c0861583ffc6b62ad0af6ee967d6 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 9 Feb 2020 13:26:24 -0800 Subject: [PATCH] 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 Reviewed-by: Jacob Keller --- interface.c | 5 +++++ interface.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/interface.c b/interface.c index 662552d0..38116794 100644 --- a/interface.c +++ b/interface.c @@ -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); +} diff --git a/interface.h b/interface.h index 371185db..5f449ae7 100644 --- a/interface.h +++ b/interface.h @@ -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