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)
#define if_setmtu(ifp, mtu) if_domtu((ifp), (mtu))
int if_carrier(struct interface *);
+#ifdef ALIAS_ADDR
+int if_makealias(char *, size_t, const char *, int);
+#endif
+
int if_carrier_os(struct interface *);
int if_mtu_os(const struct interface *);
lun = 0;
state = IPV4_STATE(ia->iface);
find_lun:
- if (lun == 0)
- strlcpy(alias, ia->iface->name, sizeof(alias));
- else
- snprintf(alias, sizeof(alias), "%s:%u", ia->iface->name, lun);
+ if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >=
+ IF_NAMESIZE)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
TAILQ_FOREACH(iap, &state->addrs, next) {
if (iap->alias[0] != '\0' && iap->addr.s_addr == INADDR_ANY) {
/* No address assigned? Lets use it. */
}
#ifdef ALIAS_ADDR
-/* Find the next logical aliase address we can use. */
+/* Find the next logical alias address we can use. */
static int
ipv6_aliasaddr(struct ipv6_addr *ia, struct ipv6_addr **repl)
{
struct ipv6_state *state;
struct ipv6_addr *iap;
- unsigned int unit;
+ unsigned int lun;
char alias[IF_NAMESIZE];
if (ia->alias[0] != '\0')
}
}
- unit = 0;
+ lun = 0;
find_unit:
- if (unit == 0)
- strlcpy(alias, ia->iface->name, sizeof(alias));
- else
- snprintf(alias, sizeof(alias), "%s:%u", ia->iface->name, unit);
+ if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >=
+ IF_NAMESIZE)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
TAILQ_FOREACH(iap, &state->addrs, next) {
if (iap->alias[0] == '\0')
continue;
}
if (iap != NULL) {
- if (unit == UINT_MAX) {
+ if (lun == UINT_MAX) {
errno = ERANGE;
return -1;
}
- unit++;
+ lun++;
goto find_unit;
}