author | max <max> | 2003-01-31 10:42:13 (UTC) |
---|---|---|
committer | max <max> | 2003-01-31 10:42:13 (UTC) |
commit | 84bd32181af3922ccba35fcaed9b404d1e4deed8 (patch) (unidiff) | |
tree | bcc5a9263db61fee555b00c0101fce9e66a74bc8 | |
parent | 9ce67a8539839d245fb009a873de2f2e63582f09 (diff) | |
download | opie-84bd32181af3922ccba35fcaed9b404d1e4deed8.zip opie-84bd32181af3922ccba35fcaed9b404d1e4deed8.tar.gz opie-84bd32181af3922ccba35fcaed9b404d1e4deed8.tar.bz2 |
promiscous flag
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 62 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | 3 |
2 files changed, 60 insertions, 5 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index d462488..def1a4b 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -68,14 +68,66 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
68 | return 1; | 68 | return 1; |
69 | } | 69 | } |
70 | 70 | ||
71 | /* Set card into promisc mode */ | 71 | /* Set card into promisc mode */ |
72 | int card_set_promisc_up (const char *device) | 72 | int card_set_promisc_up (const char *device) |
73 | { | 73 | { |
74 | char ifconfigcmd[48]; | 74 | struct ifconf ifc; |
75 | int retval=0; | 75 | struct ifreq ifr_x[50]; |
76 | u_int i; | ||
77 | int sockfd, err; | ||
78 | err=0; | ||
79 | /* opening a socket for issuing the iocalls */ | ||
80 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | ||
76 | 81 | ||
77 | snprintf(ifconfigcmd, sizeof(ifconfigcmd) - 1, SBIN_PATH, device); | 82 | if (sockfd < 0) |
78 | retval = system(ifconfigcmd); | 83 | { |
84 | /* In case of an error - mjm proove that please*/ | ||
85 | perror("socket"); | ||
86 | return 1; | ||
87 | } | ||
88 | /* Define room for 50 interfaces */ | ||
89 | ifc.ifc_len = 50 * sizeof(struct ifreq); | ||
90 | ifc.ifc_req = ifr_x; | ||
91 | /* Get the config of the interfaces */ | ||
92 | err = ioctl(sockfd, SIOCGIFCONF, &ifc); | ||
93 | if (err == -1) return 1; | ||
79 | 94 | ||
80 | return (retval ? 0 : 1); | 95 | /* For each interface*/ |
96 | for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) | ||
97 | { | ||
98 | /* To complete , should get the IP, if no is assigned, asign one */ | ||
99 | /*err = ioctl(sockfd, SIOCGIFADDR, &ifr_x[i]); | ||
100 | if (err == -1) perror("SIOCGIFADDR: "); | ||
101 | printf ("Address: %s\n",Sock_ntop_host(ifr_x[i].ifr_addr.sa_family,sizeof(ifr_x[i].ifr_addr.sa_family))); | ||
102 | */ | ||
103 | if(strncmp(ifr_x[i].ifr_name,device,5) == 0) | ||
104 | { | ||
105 | /* Get the flags */ | ||
106 | err = ioctl(sockfd, SIOCGIFFLAGS, &ifr_x[i]); | ||
107 | if (err == -1) | ||
108 | { | ||
109 | perror("SIOCGIFFLAGS: "); | ||
110 | return 1; | ||
111 | } | ||
112 | /* Check if the Interface is UP and PROMISC */ | ||
113 | if (ifr_x[i].ifr_flags & IFF_PROMISC && ifr_x[i].ifr_flags & IFF_UP) | ||
114 | { | ||
115 | /* only debug text */ | ||
116 | printf ("%s is PROMISC and UP \n",ifr_x[i].ifr_name); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | /* Set the promisc flag to the interface */ | ||
121 | ifr_x[i].ifr_flags=ifr_x[i].ifr_flags+IFF_PROMISC; | ||
122 | err = ioctl(sockfd, SIOCSIFFLAGS, &ifr_x[i]); | ||
123 | if (err == -1) | ||
124 | { | ||
125 | /* Could not set the interface into promisc mode */ | ||
126 | perror("SIOCSIFFLAGS: "); | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | /* All is fine */ | ||
132 | return 0; | ||
81 | } | 133 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 9721b39..7678202 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -7,12 +7,15 @@ | |||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <sys/types.h> | 9 | #include <sys/types.h> |
10 | #include <sys/time.h> | 10 | #include <sys/time.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <sys/ioctl.h> | ||
14 | #include <linux/if.h> | ||
15 | |||
13 | 16 | ||
14 | extern "C" | 17 | extern "C" |
15 | { | 18 | { |
16 | #include <net/bpf.h> | 19 | #include <net/bpf.h> |
17 | #include <pcap.h> | 20 | #include <pcap.h> |
18 | } | 21 | } |