[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: promiscuous mode
this will do it. it will turn promisc mode on or off.
if you're running an ids or something it should probably be taking
care of this.
# cc -o promisc promisc.c
# ./promisc fxp0
hth
-pete
/* toggle promiscuos mode on an interface by <peterw@ifost.org.au> */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <net/if.h>
#include <string.h>
#include <stdio.h>
#include <err.h>
extern char *__progname;
int
main(int argc, char **argv)
{
char *dev;
struct ifreq ifr;
short flags;
int s, i;
if (argc != 2) {
fprintf(stderr, "usage: %s <ifname>\n", __progname);
exit(1);
}
dev = argv[1];
if (dev == NULL || dev[0] == '\0' || strlen(dev) >= IFNAMSIZ)
errx(1, "invalid interface name");
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1)
err(1, "socket");
strcpy(ifr.ifr_name, dev);
i = ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr);
if (i == -1)
err(1, "SIOCGIFFLAGS");
if (ifr.ifr_flags & IFF_PROMISC) {
printf("%s -> promisc off\n", dev);
ifr.ifr_flags &= ~IFF_PROMISC;
} else {
printf("%s -> promisc on\n", dev);
ifr.ifr_flags |= IFF_PROMISC;
}
i = ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr);
if (i == -1)
err(1, "SIOCSIFFLAGS");
return(0);
}
--
"I have uncovered the very fabric of the universe. It appears to be
a kind of gingham tweed with a cross cable stitch"
IFOST: http://www.ifost.org.au - UNIX Consulting and Security