#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
用ioctl设置mac地址 得到当前的ip地址,子网掩码等信息
最新推荐文章于 2023-04-02 20:48:59 发布