C.3. Setting the Hardware Address of the Interface to Virtual MAC or Vice-Versa

 /********************************************************* NAME : hwaddr_set *********************************************************/ static int hwaddr_set( char *ifname, char *addr, int addrlen ) { struct ifreq ifr; int fd = socket(AF_INET, SOCK_DGRAM, 0); int ret; unsigned long flags; if (fd < 0) return (-1); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); /* get the flags */ ret = ioctl(fd, SIOCGIFFLAGS, (char *)&ifr); if( ret ) goto end; flags = ifr.ifr_flags; /* set the interface down */ ifr.ifr_flags &= ~IFF_UP; ret = ioctl(fd, SIOCSIFFLAGS, (char *)&ifr); if( ret ) goto end; /* change the hwaddr */ memcpy( ifr.ifr_hwaddr.sa_data, addr, addrlen ); ifr.ifr_hwaddr.sa_family ...

Get VRRP: Increasing Reliability and Failover with the Virtual Router Redundance Protocol now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.