changeset 4962:854219946ad4 draft

Linux: Support hardware address randomisation
author Roy Marples <roy@marples.name>
date Wed, 15 Jan 2020 16:07:27 +0000
parents cd7f5f9ed3cb
children c15d5bf525c1
files src/if-linux.c
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/if-linux.c	Wed Jan 15 15:49:23 2020 +0000
+++ b/src/if-linux.c	Wed Jan 15 16:07:27 2020 +0000
@@ -434,6 +434,23 @@
 }
 
 int
+if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
+{
+	struct ifreq ifr = {
+		.ifr_hwaddr.sa_family = ifp->family,
+	};
+
+	if (ifp->hwlen != maclen || maclen > sizeof(ifr.ifr_hwaddr.sa_data)) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
+	memcpy(ifr.ifr_hwaddr.sa_data, mac, maclen);
+	return if_ioctl(ifp->ctx, SIOCSIFHWADDR, &ifr, sizeof(ifr));
+}
+
+int
 if_carrier(struct interface *ifp)
 {