Penguin
Note: You are viewing an old revision of this page. View the current version.

Set I/O Control: Socket Interface Hardware Address

Sets the interface hardware address.

EXAMPLE

  1. include <sys/types.h> /* for socket(2) and related bits and pieces */
  2. include <sys/socket.h> /* for socket(2) */
  3. include <net/if.h> /* for struct ifreq */
  4. include <net/if_arp.h> /* for ARPHRD_ETHER */
  5. include <sys/ioctl.h> /* for IOCTL's */
  6. include <stdio.h> /* for fprintf etc */
  7. include <unistd.h> /* for close */

int main(int argc,char **argv) {

struct ifreq ifr; int skfd;

if (argc<3) {

fprintf(stderr,"usage:\n%s interface hwaddr\n",argv1?); return 1;

}

/* Fill in the structure / snprintf(ifr.ifr_name, IFNAMSIZ, "%s", argv1?); ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; / TODO: write some code to parse argv2? into ifr.ifr_hwaddr.sa_data / / memcpy(&ifr.ifr_hwaddr.sa_data, argv2?, sizeof(ether.address)); */

/* Create a socket fd */ skfd = socket(PF_INET,SOCK_STREAM,0);

/* call the IOCTL */ if (ioctl(skfd, SIOCSIFHWADDR, &ifr) < 0) {

perror("ioctl(SIOCSIFHWADDR)"); return 1;

}

/* cleanup */ close(skfd);

/* we're out of here! */ return 0;

}