Annotation of embedaddon/hping2/if_promisc.c, revision 1.1.1.1
1.1 misho 1: /*
2: * $smu-mark$
3: * $name: if_promisc.c$
4: * $author: Salvatore Sanfilippo <antirez@invece.org>$
5: * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6: * $license: This software is under GPL version 2 of license$
7: * $date: Fri Nov 5 11:55:48 MET 1999$
8: * $rev: 2$
9: */
10:
11: #include <sys/types.h>
12: #include <sys/ioctl.h>
13: #include <string.h>
14: #include <stdio.h>
15: #include <netinet/in.h>
16: #include <sys/socket.h>
17: #include <net/if.h>
18:
19: #include "hping2.h"
20: #include "globals.h"
21:
22: int if_promisc_on(int s)
23: {
24: struct ifreq ifr;
25:
26: strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
27: if ( ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
28: perror("[open_sockpacket] ioctl(SIOCGIFFLAGS)");
29: return -1;
30: }
31:
32: if (!(ifr.ifr_flags & IFF_PROMISC)) {
33: ifr.ifr_flags |= IFF_PROMISC;
34: if ( ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
35: perror("[open_sockpacket] ioctl(SIOCSIFFLAGS)");
36: return -1;
37: }
38: }
39: return 0;
40: }
41:
42: int if_promisc_off(int s)
43: {
44: struct ifreq ifr;
45:
46: strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
47: if ( ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
48: perror("[open_sockpacket] ioctl(SIOCGIFFLAGS)");
49: return -1;
50: }
51:
52: if (ifr.ifr_flags & IFF_PROMISC) {
53: ifr.ifr_flags ^= IFF_PROMISC;
54: if ( ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
55: perror("[open_sockpacket] ioctl(SIOCSIFFLAGS)");
56: return -1;
57: }
58: }
59: return 0;
60: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>