1. 程式人生 > >ioctl設定或查詢無線網絡卡資訊

ioctl設定或查詢無線網絡卡資訊

ioctl查詢無線網絡卡資訊

 

 

#include<unistd.h>
#include<sys/ioctl.h>

int ioctl( int fd, int request,.../* void *arg */ );
//返回0:成功   -1:出錯 //第三個引數總是一個指標,但指標的型別依賴於request引數。

request 引數定義如下:
/* -------------------------- IOCTL LIST-------------------------- */
/* Basic operations */

#define SIOCSIWCOMMIT      0x8B00          /* 提交修改結果 */

#define SIOCGIWNAME    0x8B01          /* 獲取裝置名字 */

#define SIOCSIWNWID     0x8B02          /* 設定網路ID */

#define SIOCGIWNWID 0x8B03 /* 獲取網路ID */ #define SIOCSIWFREQ 0x8B04 /* 設定通道(頻率) */ #define SIOCGIWFREQ 0x8B05 /* 獲取通道(頻率) */ #define SIOCSIWMODE 0x8B06 /* 設定網絡卡模式*/ #define SIOCGIWMODE 0x8B07 /* 獲取網絡卡模式 */ #define SIOCSIWSENS 0x8B08 /* 設定靈敏度(dBm) */ #define SIOCGIWSENS 0x8B09 /* 獲取靈敏度 (dBm) */ /* Informative stuff */ #define SIOCSIWRANGE 0x8B0A /* Unused */ #define SIOCGIWRANGE 0x8B0B /* 獲取引數範圍 */ #define SIOCSIWPRIV 0x8B0C /* Unused */ #define SIOCGIWPRIV 0x8B0D /* 獲取網絡卡特有的ioctl介面 */ #define SIOCSIWSTATS 0x8B0E /* Unused */ #define SIOCGIWSTATS 0x8B0F /* 獲取 /proc/net/wireless的stats */ /* Mobile IP support */ #define SIOCSIWSPY 0x8B10 /* 設定spy 地址*/ #define SIOCGIWSPY 0x8B11 /* 獲取spy資訊(連線質量) */ /* Access Point manipulation */ #define SIOCSIWAP 0x8B14 /* 設定AP的mac地址 */ #define SIOCGIWAP 0x8B15 /* 獲取AP的mac地址 */ #define SIOCGIWAPLIST 0x8B17 /* 獲取周圍Ap資訊列表 */ #define SIOCSIWSCAN 0x8B18 /* 開始掃描 */ #define SIOCGIWSCAN 0x8B19 /* 獲取掃描資訊 */ /* 802.11 specific support */ #define SIOCSIWESSID 0x8B1A /* 設定ESSID */ #define SIOCGIWESSID 0x8B1B /* 獲取ESSID */ #define SIOCSIWNICKN 0x8B1C /* 設定節點別名 */ #define SIOCGIWNICKN 0x8B1D /* 獲取節點別名 */ /* As the ESSID and NICKN are strings upto 32 bytes long, it doesn't fit * within the 'iwreq' structure, sowe need to use the 'data' member to * point to a string in user space,like it is done for RANGE... * The "flags" memberindicate if the ESSID is active or not (promiscuous). */ /* Other parameters useful in 802.11 andsome other devices */ #define SIOCSIWRATE 0x8B20 /* 設定預設傳輸速率(bps) */ #define SIOCGIWRATE 0x8B21 /* 獲取預設傳輸速率 (bps) */ #define SIOCSIWRTS 0x8B22 /* 設定 RTS/CTS 的臨界值(bytes) */ #define SIOCGIWRTS 0x8B23 /* 獲取 RTS/CTS 的臨界值 (bytes) */ #define SIOCSIWFRAG 0x8B24 /* 設定分片傳輸的包大小 (bytes) */ #define SIOCGIWFRAG 0x8B25 /* 獲取分片傳輸的包大小 (bytes)*/ #define SIOCSIWTXPOW 0x8B26 /* 設定傳輸功率 (dBm) */ #define SIOCGIWTXPOW 0x8B27 /* 獲取傳輸功率(dBm) */ #define SIOCSIWRETRY 0x8B28 /* 設定重傳次數和生存時間 */ #define SIOCGIWRETRY 0x8B29 /* 獲取重傳次數和生存時間 */ /* Encoding stuff (scrambling, hardwaresecurity, WEP...) */ #define SIOCSIWENCODE 0x8B2A /* 設定編碼模式 */ #define SIOCGIWENCODE 0x8B2B /* 獲取編碼模式 */ /* Power saving stuff (power management,unicast and multicast) */ #define SIOCSIWPOWER 0x8B2C /* 設定電源管理模式 */ #define SIOCGIWPOWER 0x8B2D /* 獲取電源管理模式*/ /* -------------------- DEV PRIVATE IOCTLLIST -------------------- */ /* These 16 ioctl are wireless deviceprivate. * Each driver is free to use themfor whatever purpose it chooses, * however the driver *must* exportthe description of those ioctls * with SIOCGIWPRIV and *must* usearguments as defined below. * If you don't follow those rules,DaveM is going to hate you (reason : * it make mixed 32/64bit operationimpossible). */ #define SIOCIWFIRSTPRIV 0x8BE0 #define SIOCIWLASTPRIV 0x8BFF /* Previously, we were usingSIOCDEVPRIVATE, but we now have our * separate range because ofcollisions with other tools such as * 'mii-tool'. * We now have 32 commands, so a bitmore space ;-). * Also, all 'odd' commands are onlyusable by root and don't return the * content of ifr/iwr to user (butyou are not obliged to use the set/get * convention, just use every othertwo command). * And I repeat : you are not obligedto use them with iwspy, but you * must be compliant with it. */ /* ------------------------- IOCTL STUFF------------------------- */ /* The first and the last (range) */ #define SIOCIWFIRST 0x8B00 #define SIOCIWLAST SIOCIWLASTPRIV /* 0x8BFF */