From b802e3b7840b0065560cb284e3d5df7f549b41d6 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 9 Feb 2020 11:40:24 -0800 Subject: [PATCH] interface: Introduce a method to initialize the time stamping label. In many cases, the time stamping label will be the same as the name of the interface. In order to prevent users from open coding the logic that initializes the label from the interface name, this patch add an appropriate method. Signed-off-by: Richard Cochran Reviewed-by: Jacob Keller --- interface.c | 7 +++++++ interface.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/interface.c b/interface.c index 460ceb8..662552d 100644 --- a/interface.c +++ b/interface.c @@ -6,6 +6,13 @@ */ #include "interface.h" +void interface_ensure_tslabel(struct interface *iface) +{ + if (!iface->ts_label[0]) { + strncpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE); + } +} + int interface_get_tsinfo(struct interface *iface) { return sk_get_ts_info(iface->ts_label, &iface->ts_info); diff --git a/interface.h b/interface.h index 05cfb10..371185d 100644 --- a/interface.h +++ b/interface.h @@ -24,6 +24,12 @@ struct interface { struct sk_ts_info ts_info; }; +/** + * Ensures that an interface has a proper time stamping label. + * @param iface The interface of interest. + */ +void interface_ensure_tslabel(struct interface *iface); + /** * Populate the time stamping information of a given interface. * @param iface The interface of interest.