LINUX下獲取IP位址和MAC位址

2021-04-13 03:15:31 字數 1512 閱讀 7552

#include

#include

#include

#include

#include

#include

#include

#include

#ifdef solaris

#include

#endif

#define maxinte***ces   16

main (argc, argv)

register int argc;

register char *argv; }

else

//判斷網絡卡狀態

if (buf[int***ce].ifr_flags & iff_up)

else

//獲取當前網絡卡的ip位址

if (!(ioctl (fd, siocgifaddr, (char *) &buf[int***ce])))

else

/* this section can't get hardware address,i don't know whether the reason is module driver*/

#ifdef solaris

//獲取mac位址

arp.arp_pa.sa_family = af_inet;

arp.arp_ha.sa_family = af_inet;

((struct sockaddr_in*)&arp.arp_pa)->sin_addr.s_addr=((struct sockaddr_in*)(&buf[int***ce].ifr_addr))->sin_addr.s_addr;

if (!(ioctl (fd, siocgarp, (char *) &arp)))

#else

#if 0

/*get hw address of the net card */

if (!(ioctl (fd,  siocgenaddr, (char *) &buf[int***ce])))

#endif

if (!(ioctl (fd, siocgifhwaddr, (char *) &buf[int***ce])))

#endif

else

} //while

} else

perror ("cpm: ioctl");

} else

perror ("cpm: socket");

close (fd);

return retn;

}

LINUX下獲取IP位址和MAC位址

判斷網絡卡狀態 if buf int ce ifr flags iff up else 獲取當前網絡卡的ip位址 if ioctl fd,siocgifaddr,char buf int ce else this section can t get hardware address,i don t ...

LINUX下獲取IP位址和MAC位址

gcc o mac mac.c include include include include include include include include ifdef solaris include endif define maxinte ces 16 main argc,argv regis...

linux 下獲取本地IP位址

include include include include include include include include include include include include include include int main int argc,char argv int getloc...