#include <sio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#define MAXINTERFACES 16
main (argc, argv)
register int argc;
register char *argv[];
{
register int fd, inface, retn = 0;
suct ifreq buf[MAXINTERFACES];
suct arpreq arp;
suct ifconf ifc;
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >= 0) {
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = (caddr_t) buf;
if (!ioctl (fd, SIOCGIFCONF, (char *) &ifc)) {
inface = ifc.ifc_len / sizeof (suct ifreq);
printf("interface num is inface=%d\n\n\n",inface);
while (inface-- > 0)
{
printf ("net device %s\n", buf[inface].ifr_name);
/*Jugde whether the net card status is promisc*/
if (!(ioctl (fd, SIOCGIFFLAGS, (char *) &buf[inface]))) {
if (buf[inface].ifr_flags & IFF_PROMISC) {
puts ("the interface is PROMISC");
retn ;
}
} else {
char s[256];
sprintf (s, "cpm: ioctl device %s", buf[inface].ifr_name);
perror (s);
}
/*Jugde whether the net card status is up*/
if (buf[inface].ifr_flags & IFF_UP) {
puts("the interface status is UP");
}
else {
puts("the interface status is DOWN");
}
/*Get IP of the net card */
if (!(ioctl (fd, SIOCGIFADDR, (char *) &buf[inface])))
{
puts ("IP address is:");
puts(inet_ntoa(((suct sockaddr_in*)(&buf[inface].ifr_addr))->sin_addr));
puts("");
//puts (buf[inface].ifr_addr.sa_data);
}
else {
char s[256];
sprintf (s, "cpm: ioctl device %s", buf[inface].ifr_name);
perror (s);
}
/*Get HW ADDRESS of the net card */
if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[inface])))
{
puts ("HW address is:");
printf("x:x:x:x:x:x\n",
(unsigned char)buf[inface].ifr_hwaddr.sa_data[0],
(unsigned char)buf[inface].ifr_hwaddr.sa_data[1],
(unsigned char)buf[inface].ifr_hwaddr.sa_data[2],
(unsigned char)buf[inface].ifr_hwaddr.sa_data[3],
(unsigned char)buf[inface].ifr_hwaddr.sa_data[4],
(unsigned char)buf[inface].ifr_hwaddr.sa_data[5]);
puts("");
puts("");
}
else {
char s[256];
sprintf (s, "cpm: ioctl device %s", buf[inface].ifr_name);
perror (s);
}
}
} else
perror ("cpm: ioctl");
} else
perror ("cpm: socket");
close (fd);
return retn;
}