author | max <max> | 2003-02-07 03:23:16 (UTC) |
---|---|---|
committer | max <max> | 2003-02-07 03:23:16 (UTC) |
commit | 2e7e176817b5d162b054f97ed6650e659730f4ae (patch) (unidiff) | |
tree | 6b64a6ab7cbef944a564eabe6f63d8ac89eafefc /noncore | |
parent | 9062b40d50264bc479ee0425778c552ef20ee304 (diff) | |
download | opie-2e7e176817b5d162b054f97ed6650e659730f4ae.zip opie-2e7e176817b5d162b054f97ed6650e659730f4ae.tar.gz opie-2e7e176817b5d162b054f97ed6650e659730f4ae.tar.bz2 |
Flags and datalink
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 106 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | 2 |
2 files changed, 60 insertions, 48 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index def1a4b..1add34c 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -25,3 +25,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
25 | { | 25 | { |
26 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); | 26 | wl_logerr("Cannot set interface to promisc mode"); |
27 | return 0; | 27 | return 0; |
@@ -67,67 +67,77 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
67 | 67 | ||
68 | return 1; | 68 | /* Setting the promiscous and up flag to the interface */ |
69 | } | 69 | if (!card_check_rfmon_datalink(device)) |
70 | |||
71 | /* Set card into promisc mode */ | ||
72 | int card_set_promisc_up (const char *device) | ||
73 | { | 70 | { |
74 | struct ifconf ifc; | 71 | wl_logerr("Cannot set interface to rfmon mode"); |
75 | struct ifreq ifr_x[50]; | 72 | return 0; |
76 | u_int i; | 73 | } |
77 | int sockfd, err; | 74 | else |
78 | err=0; | ||
79 | /* opening a socket for issuing the iocalls */ | ||
80 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | ||
81 | |||
82 | if (sockfd < 0) | ||
83 | { | 75 | { |
84 | /* In case of an error - mjm proove that please*/ | 76 | wl_loginfo("Interface set to rfmon mode"); |
85 | perror("socket"); | 77 | } |
86 | return 1; | 78 | return 1; |
87 | } | 79 | } |
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; | ||
94 | 80 | ||
95 | /* For each interface*/ | 81 | /* Check card is in the rfmon mode */ |
96 | for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) | 82 | int card_check_rfmon_datalink (char *device) |
97 | { | 83 | { |
98 | /* To complete , should get the IP, if no is assigned, asign one */ | 84 | int datalinktype=0; |
99 | /*err = ioctl(sockfd, SIOCGIFADDR, &ifr_x[i]); | 85 | pcap_t *phandle; |
100 | if (err == -1) perror("SIOCGIFADDR: "); | 86 | phandle = pcap_open_live(device, 65,0,0,NULL); |
101 | printf ("Address: %s\n",Sock_ntop_host(ifr_x[i].ifr_addr.sa_family,sizeof(ifr_x[i].ifr_addr.sa_family))); | 87 | datalinktype = pcap_datalink (phandle); |
102 | */ | 88 | |
103 | if(strncmp(ifr_x[i].ifr_name,device,5) == 0) | 89 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
104 | { | 90 | { |
105 | /* Get the flags */ | 91 | return 0; |
106 | err = ioctl(sockfd, SIOCGIFFLAGS, &ifr_x[i]); | 92 | } |
107 | if (err == -1) | 93 | else |
108 | { | 94 | { |
109 | perror("SIOCGIFFLAGS: "); | 95 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); |
110 | return 1; | 96 | return 1; |
111 | } | 97 | } |
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 | } | 98 | } |
118 | else | 99 | |
100 | /* Set card into promisc mode */ | ||
101 | int card_set_promisc_up (const char *device) | ||
119 | { | 102 | { |
120 | /* Set the promisc flag to the interface */ | 103 | int err; |
121 | ifr_x[i].ifr_flags=ifr_x[i].ifr_flags+IFF_PROMISC; | 104 | /* First generate a socket to use with iocalls */ |
122 | err = ioctl(sockfd, SIOCSIFFLAGS, &ifr_x[i]); | 105 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
123 | if (err == -1) | 106 | if (fd < 0) |
124 | { | 107 | { |
125 | /* Could not set the interface into promisc mode */ | 108 | /* In case of an error */ |
126 | perror("SIOCSIFFLAGS: "); | 109 | perror("socket"); |
110 | return 0; | ||
127 | } | 111 | } |
112 | |||
113 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | ||
114 | struct ifreq ifr; | ||
115 | strncpy(ifr.ifr_name, device,10); | ||
116 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | ||
117 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | ||
118 | if (err < 0) | ||
119 | { | ||
120 | perror("Could not access the interface, "); | ||
121 | return 0; | ||
128 | } | 122 | } |
123 | |||
124 | /* Get the informations back from the interface to check if the flags are correct */ | ||
125 | strncpy(ifr.ifr_name, device,10); | ||
126 | ioctl(fd, SIOCGIFFLAGS, &ifr); | ||
127 | if (err < 0) | ||
128 | { | ||
129 | perror("Could not access the interface, "); | ||
130 | return 0; | ||
129 | } | 131 | } |
132 | |||
133 | if(ifr.ifr_flags && IFF_UP) | ||
134 | { | ||
135 | printf("%s is ok\n", device); | ||
136 | return 1; | ||
130 | } | 137 | } |
131 | /* All is fine */ | 138 | else |
139 | { | ||
140 | printf("%s flags could not be set", device); | ||
132 | return 0; | 141 | return 0; |
133 | } | 142 | } |
143 | } | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 7750fb6..babb109 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -12,2 +12,3 @@ | |||
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <arpa/inet.h> | ||
13 | #include <sys/ioctl.h> | 14 | #include <sys/ioctl.h> |
@@ -37,2 +38,3 @@ extern "C" | |||
37 | /* Prototypes */ | 38 | /* Prototypes */ |
39 | int card_check_rfmon_datalink (char *device); | ||
38 | int card_into_monitormode (pcap_t **, char *, int); | 40 | int card_into_monitormode (pcap_t **, char *, int); |