/* This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #ifndef SIOCIWFIRSTPRIV #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE #endif /*===============================================================*/ /* Declarations */ //With thanks to the linux-wlan-ng project #define WLAN_DEVNAMELEN_MAX 16 #define P80211ENUM_truth_false 0 #define P80211ENUM_truth_true 1 #define P80211ENUM_msgitem_status_no_value 1 /*===============================================================*/ /* Types */ /*----------------------------------------------------------------*/ /* A ptr to the following structure type is passed as the third */ /* argument to the ioctl system call when issuing a request to */ /* the p80211 module. */ /* message data item for INT, BOUNDEDINT, ENUMINT */ typedef struct p80211item_uint32 { uint32_t did; uint16_t status; uint16_t len; uint32_t data; } p80211item_uint32_t; #define DIDmsg_lnxreq_wlansniff 0x0043 #define DIDmsg_lnxreq_wlansniff_enable 0x1043 #define DIDmsg_lnxreq_wlansniff_channel 0x2043 #define DIDmsg_lnxreq_wlansniff_resultcode 0x3043 typedef struct p80211msg_lnxreq_wlansniff { uint32_t msgcode; uint32_t msglen; uint8_t devname[WLAN_DEVNAMELEN_MAX]; p80211item_uint32_t enable; p80211item_uint32_t channel; p80211item_uint32_t resultcode; } p80211msg_lnxreq_wlansniff_t; void usage(char *name) { fprintf(stderr, "usage: %s [-i devname] [-d | -e channel]\n", name); fprintf(stderr, "\t-i to specify your Orinoco device name (default eth0)\n"); fprintf(stderr, "\t-d to disable monitor mode\n"); fprintf(stderr, "\t-e to enable monitor mode and specify channel (default 6)\n"); exit(1); } int main(int argc, char **argv) { p80211msg_lnxreq_wlansniff_t sniff; char dev[WLAN_DEVNAMELEN_MAX + 1] = "eth0"; int channel = 6; int enable = 0; int result = -1; int fd; struct iwreq ireq; //for Orinoco while(1) { result = getopt(argc, argv, "i:e:d"); if (result < 0) break; switch (result) { case 'i': strncpy(dev, optarg, WLAN_DEVNAMELEN_MAX); dev[WLAN_DEVNAMELEN_MAX] = 0; break; case 'd': enable = 0; break; case 'e': channel = atoi(optarg); enable = 1; break; default: usage(argv[0]); } } memset(&sniff, 0, sizeof(p80211msg_lnxreq_wlansniff_t)); sniff.msgcode = DIDmsg_lnxreq_wlansniff; sniff.msglen = sizeof(p80211msg_lnxreq_wlansniff_t); strcpy((char*) sniff.devname, dev); sniff.enable.did = DIDmsg_lnxreq_wlansniff_enable; sniff.enable.len = 4; sniff.enable.data = enable ? P80211ENUM_truth_true : P80211ENUM_truth_false; sniff.channel.did = DIDmsg_lnxreq_wlansniff_channel; sniff.channel.len = 4; sniff.channel.data = channel; sniff.resultcode.did = DIDmsg_lnxreq_wlansniff_resultcode; sniff.resultcode.status = P80211ENUM_msgitem_status_no_value; sniff.resultcode.len = 4; /* get a socket */ fd = socket(AF_INET, SOCK_STREAM, 0); if ( fd == -1 ) { return result; } ireq.u.data.pointer = (caddr_t) &sniff; strcpy(ireq.ifr_ifrn.ifrn_name, dev); result = ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq); close(fd); if (result) { fprintf(stderr, "failed\n"); } else { fprintf(stderr, "success\n"); } return result; }