static int get_ifindex(const struct netdev *, int *ifindexp);
static int get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN],
int *hwaddr_familyp);
+static int set_etheraddr(const char *netdev_name, int hwaddr_family,
+ const uint8_t[ETH_ADDR_LEN]);
/* Obtains the IPv6 address for 'name' into 'in6'. */
static void
int
netdev_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN])
{
- struct ifreq ifr;
-
- memset(&ifr, 0, sizeof ifr);
- strncpy(ifr.ifr_name, netdev->name, sizeof ifr.ifr_name);
- ifr.ifr_hwaddr.sa_family = netdev->hwaddr_family;
- memcpy(ifr.ifr_hwaddr.sa_data, mac, ETH_ADDR_LEN);
- if (ioctl(netdev->netdev_fd, SIOCSIFHWADDR, &ifr) < 0) {
- VLOG_ERR("ioctl(SIOCSIFHWADDR) on %s device failed: %s",
- netdev->name, strerror(errno));
- return errno;
+ int error = set_etheraddr(netdev->name, netdev->hwaddr_family, mac);
+ if (!error) {
+ memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
}
- memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
- return 0;
+ return error;
+}
+
+int
+netdev_nodev_set_etheraddr(const char *name, const uint8_t mac[ETH_ADDR_LEN])
+{
+ init_netdev();
+ return set_etheraddr(name, ARPHRD_ETHER, mac);
}
/* Returns a pointer to 'netdev''s MAC address. The caller must not modify or
}
}
memcpy(ea, ifr.ifr_hwaddr.sa_data, ETH_ADDR_LEN);
+ return 0;
+}
+static int
+set_etheraddr(const char *netdev_name, int hwaddr_family,
+ const uint8_t mac[ETH_ADDR_LEN])
+{
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof ifr);
+ strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
+ ifr.ifr_hwaddr.sa_family = hwaddr_family;
+ memcpy(ifr.ifr_hwaddr.sa_data, mac, ETH_ADDR_LEN);
+ if (ioctl(af_inet_sock, SIOCSIFHWADDR, &ifr) < 0) {
+ VLOG_ERR("ioctl(SIOCSIFHWADDR) on %s device failed: %s",
+ netdev_name, strerror(errno));
+ return errno;
+ }
return 0;
}