-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromisc.c
More file actions
55 lines (39 loc) · 1.18 KB
/
promisc.c
File metadata and controls
55 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* name: promisc.c
* this file is part of the "Net-Injector" project. It defines the set_promisc() function
* Copyright (C) 2002 by Jean Philippe GUILLEMIN <jp.guillemin@free.fr>
* license: This software is under GPL license
* date: 04 17 2003
* rev: 0.8
*/
#include "neti.h"
int set_promisc(int sock) {
struct ifreq ifr;
memset(&ifr, 0, IFREQ_SIZE);
strncpy(ifr.ifr_name, myhdr->interface, 32);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0){
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0){
fprintf(stderr, "Error : cant set promiscuous mode !\n");
}
}else{
fprintf(stderr, "Error : (set_promisc) in call to ioctl() !\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int unset_promisc(int sock) {
struct ifreq ifr;
memset(&ifr, 0, IFREQ_SIZE);
strncpy(ifr.ifr_name, myhdr->interface, 32);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0){
ifr.ifr_flags ^= IFF_PROMISC;
if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0){
fprintf(stderr, "Erroro : cant unset promiscuous mode !\n");
}
}else{
fprintf(stderr, "Error : (unset_promisc) in call to ioctl() !\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}