Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
SIOCSIFHWADDR
Edit
PageHistory
Diff
Info
LikePages
!!!__S__et __I__/__O__ __C__ontrol: __S__ocket __I__nter__f__ace __H__ard__w__are __Addr__ess Sets the interface hardware address. !!EXAMPLE <verbatim> #include <sys/types.h> /* for socket(2) and related bits and pieces */ #include <sys/socket.h> /* for socket(2) */ #include <net/if.h> /* for struct ifreq */ #include <net/if_arp.h> /* for ARPHRD_ETHER */ #include <sys/ioctl.h> /* for IOCTL's */ #include <stdio.h> /* for fprintf etc */ #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",argv[1]); return 1; } /* Fill in the structure */ snprintf(ifr.ifr_name, IFNAMSIZ, "%s", argv[1]); ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; /* TODO: write some code to parse argv[2] into ifr.ifr_hwaddr.sa_data */ /* memcpy(&ifr.ifr_hwaddr.sa_data, argv[2], 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; } </verbatim>
One page links to
SIOCSIFHWADDR
:
ioctl_list(2)