summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-04-16 18:12:16 +0000
committerRoy Marples <roy@marples.name>2019-04-16 18:12:16 +0000
commit504b658e5bb3f5c96c57c80d1edb0c107b62e559 (patch)
treece8636e5f4904d6d5fb25a7777889aa9c1e798ad /src/if.c
parentc1209152039f7fa4fa84958f521948f187e78eae (diff)
downloaddhcpcd-504b658e5bb3f5c96c57c80d1edb0c107b62e559.tar.xz
if: Add a generic function to create an aliased address name
Reduces complexity between IPv4 and IPv6 and silences a warning about potential string trunctaion if the LUN makes too big an interface name.
Diffstat (limited to 'src/if.c')
-rw-r--r--src/if.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/if.c b/src/if.c
index 783a92bb..efc4314c 100644
--- a/src/if.c
+++ b/src/if.c
@@ -784,6 +784,17 @@ if_cmp(const struct interface *si, const struct interface *ti)
return 0;
}
+#ifdef ALIAS_ADDR
+int
+if_makealias(char *alias, size_t alias_len, const char *ifname, int lun)
+{
+
+ if (lun == 0)
+ return strlcpy(alias, ifname, alias_len);
+ return snprintf(alias, alias_len, "%s:%u", ifname, lun);
+}
+#endif
+
/* Sort the interfaces into a preferred order - best first, worst last. */
void
if_sortinterfaces(struct dhcpcd_ctx *ctx)