
/* OPEN PROMISCUOUS SOCKET */
if ((sd = socket (AF_INET, SOCK_PACKET,
htons (ETH_P_ALL))) < 0) {
perror ("Can’t get socket: ");
exit (1);
}
/* SET PROMISC */
strcpy (oldifr.ifr_name, device);
if (ioctl (sd, SIOCGIFFLAGS, &oldifr) < 0) {
close (sd);
perror ("Can’t get flags: ");
exit (2);
}
ifr = oldifr;
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl (sd, SIOCSIFFLAGS, &ifr) < 0) {
close (sd);
perror ("Can’t set flags: ");
exit (3);
}
while (TRUE) {
/* This is the main data-gathering loop */
sizeaddr = SN_RCV_BUF_SIZE;
length = recvfrom (sd, buf,
SN_RCV_BUF_SIZE,
0, &saddr, &sizeaddr);
if (length > 0)
handle_frame (buf, length, &saddr);
}
This document was produced using groff-1.19.