⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib80211.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
📖 第 1 页 / 共 3 页
字号:
   	\return The number of items in the extended cache of the specified interface   	Performs same ioctl call as getExtendedCache, but throws away all data except the number of items.	Useful for allocating memory for a subsequent getExtendedCache call.*/int getCacheItemnr(const char *iface) {	struct wi_req wreq;	int *items;		bzero((char *) &wreq, sizeof(struct wi_req));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = WI_RID_READ_EXTCACHE;	getVal(iface, &wreq);	items = (int *) wreq.wi_val;	return *items;}/*! 	\fn int getEWMAConst_bw(const char *iface)	\brief Gets the EWMA constant used by the driver to calculate the (EWM) average of the bandwidth for the specified interface	\param iface The name of the interface	\return The EWMA constant, times 1000.	For the EWMA constant as used by the driver, c, we have \f$0 < c < 1\f$, c being floating point. We convert this value to 	integer (for the snmpd, as Floats and other Opaque Objects are forbidden in SMIv2) by multiplying	by 1000 and truncating.*/int getEWMAConst_bw(const char *iface) {	struct wi_req wreq;	int *c;	bzero((char *) &wreq, sizeof(struct wi_req));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_READ_EWMACONSTBW;        getVal(iface, &wreq);	c = (int *) wreq.wi_val;	return *c;}/*! 	\fn int getEWMAConst_snq(const char *iface)	\brief Gets the EWMA constant used by the driver to calculate the (EWM) average of signal strength,		noise level and link quality for the specified interface.	\param iface The name of the interface	\return The EWMA constant, times 1000.	For the EWMA constant as used by the driver, c,  we have \f$0 < c < 1\f$, c being floating point. We convert this value to 	integer (for the snmpd, as Floats and other Opaque Objects are forbidden in SMIv2) by multiplying	by 1000 and truncating.*/int getEWMAConst_snq(const char *iface) {        struct wi_req wreq;        int *c;        bzero((char *) &wreq, sizeof(struct wi_req));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_READ_EWMACONSTSNQ;        getVal(iface, &wreq);        c = (int *) wreq.wi_val;        return *c;}/*! 	\fn void setEWMAConst_bw(const char *iface, int c)	\brief Sets the EWMA constant used by the driver to calculate the (EWM) average of the bandwidth for the specified interface	\param iface The name of the interface	\param c The EWMA constant, times 1000	For the EWMA constant c we have \f$1 <= c <= 1000\f$, c being integer. We convert this value to 	floating point (as used by the driver) by dividing by 1000.*/void setEWMAConst_bw(const char *iface, int c) {	struct wi_req           wreq;        bzero((char *)&wreq, sizeof(wreq));        wreq.wi_type = WI_RID_WRITE_EWMACONSTBW;        wreq.wi_len = sizeof(int) /2;        bcopy((char *) &c, (char *) &wreq.wi_val, sizeof(int));        setVal(iface, &wreq);}/*! 	\fn void setEWMAConst_snq(const char *iface, int c)	\brief Sets the EWMA constant used by the driver to calculate the (EWM) average of signal strength,		noise level and link quality for the specified interface	\param iface The name of the interface	\param c The EWMA constant, times 1000	For the EWMA constant c we have \f$1 <= c <= 1000\f$, c being integer. We convert this value to 	floating point (as used by the driver) by dividing by 1000.*/void setEWMAConst_snq(const char *iface, int c) {	struct wi_req           wreq;        bzero((char *)&wreq, sizeof(wreq));        wreq.wi_type = WI_RID_WRITE_EWMACONSTSNQ;        wreq.wi_len = sizeof(int) /2;        bcopy((char *) &c, (char *) &wreq.wi_val, sizeof(int));        setVal(iface, &wreq);}/*!	\fn u_int16_t getTimeoutTime(const char *iface) 	\brief Gets the cache timeout value from the driver, for the specified interface	\param iface The name of the interface	\return The cache timeout value, in seconds	The cache timeout value is used to indicate the number of seconds that should pass before an 'idle' cache entry is removed. Idle is a little bit more complex (has to do with the mode of the interface, the type of entry (unicast, multicast, broadcast) but basically it means not sending, nor receiving nor being associated with the interface.*/u_int16_t getTimeoutTime(const char *iface) {	struct wi_req		wreq;	bzero((char *) &wreq, sizeof(struct wi_req));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_READ_TIMEOUT_TIME;        getVal(iface, &wreq);	return wreq.wi_val[0];}/*!	\fn void setTimeoutTime(const char *iface, u_int16_t t) 	\brief Sets the cache timeout value from the driver, for the specified interface	\param iface The name of the interface	\param t The cache timeout value, in seconds	The cache timeout value is used to indicate the number of seconds that should pass before an 'idle' cache entry is removed. Idle is a little bit more complex (has to do with the mode of the interface, the type of entry (unicast, multicast, broadcast) but basically it means not sending, nor receiving nor being associated with the interface.*/void setTimeoutTime(const char *iface, u_int16_t t) {	setWord(iface, WI_RID_WRITE_TIMEOUT_TIME, t);}/********************************************************************//*!	\fn void getVal(const char *iface, struct wi_req *wreq) 	\brief Performs the SIOCGWAVELAN ioctl call to get a value 	\param iface The name of the interface	\param wreq Pointer to an allocated and set-up wi_req structure. The structure must specify the type of request etc. 	\note Code has been ripped from wicontrol.c		The wi_req structure is passed to the driver via the ioctl call. The driver (if request type is valid) copies the requested information in the structure. Thus, on exit wreq contains the information.*/void getVal(const char *iface, struct wi_req *wreq){	struct ifreq		ifr;	int			s;	bzero((char *)&ifr, sizeof(ifr));	strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));	ifr.ifr_data = (caddr_t)wreq;	s = socket(AF_INET, SOCK_DGRAM, 0);	if (s == -1)		err(1, "socket");	if (ioctl(s, SIOCGWAVELAN, &ifr) == -1)		err(1, "SIOCGWAVELAN");	if (close(s) < 0)		err(1, "close socket");	return;}/*!	\fn void setVal(const char *iface, struct wi_req *wreq) 	\brief Performs the SIOCSWAVELAN ioctl call to set a value 	\param iface The name of the interface	\param wreq Pointer to an allocated and set-up wi_req structure. The structure must specify the type of request, have the right data format etc. 	\note Code has been ripped from wicontrol.c		The wi_req structure is passed to the driver via the ioctl call. The driver acts according to the request type and data present in this structure.*/void setVal(const char *iface, struct wi_req *wreq){	struct ifreq		ifr;	int			s;	bzero((char *)&ifr, sizeof(ifr));	strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));	ifr.ifr_data = (caddr_t)wreq;	s = socket(AF_INET, SOCK_DGRAM, 0);	if (s == -1)		err(1, "socket");	if (ioctl(s, SIOCSWAVELAN, &ifr) == -1)		err(1, "SIOCSWAVELAN");	if (close(s) < 0)		err(1, "close socket");	return;}/*!	\fn void setWord(const char *iface, int code, u_int16_t word) 	\brief Uses setVal to specifically set a word value for a specific request type. 	\param iface The name of the interface	\param code Type of the request	\param word The word (2 byte) value that should be set	\note Code has been ripped from wicontrol.c*/void setWord(const char *iface, int code, u_int16_t word){	struct wi_req		wreq;	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_type = code;	wreq.wi_len = 2;	wreq.wi_val[0] = word;	setVal(iface, &wreq);	return;}/*!	\fn u_int16_t getWord(const char *iface, int type) 	\brief Uses getVal to specifically get a word value for a specific request type. 	\param iface The name of the interface	\param type Type of the request	\return The word value of the specific request type	\note Code has been ripped from wicontrol.c*/u_int16_t getWord(const char *iface, int type) {	struct wi_req wreq;	bzero((char *) &wreq, sizeof(wreq));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = type;	getVal(iface, &wreq);		return wreq.wi_val[0];}/*!	\fn void setStr(const char *iface, int code, char *str) 	\brief Uses setVal to specifically set a string value for a specific request type. 	\param iface The name of the interface	\param code Type of the request	\param str The string (null-terminated) value that should be set	\note Code has been ripped from wicontrol.c	\warning Since this function will mainly be used for setting of the SSID en Stationname, str has a maximum length of 30.*/void setStr(const char *iface, int code, char *str){        struct wi_req           wreq;        if (iface == NULL)                errx(1, "must specify interface name");        if (str == NULL)                errx(1, "must specify string");        bzero((char *)&wreq, sizeof(wreq));        if (strlen(str) > 30)                errx(1, "string too long");        wreq.wi_type = code;        wreq.wi_len = 18;        wreq.wi_val[0] = strlen(str);        bcopy(str, (char *)&wreq.wi_val[1], strlen(str));        setVal(iface, &wreq);        return;}/*!	\fn void setDesiredSSID(const char *iface, char *str) 	\brief Sets the desired SSID of the interface to the specified value  	\param iface The name of the interface	\param str The string (null-terminated) value that the desired SSID should be set to	\note This function calls the setStr function, and thus uses SIOCSWAVELAN*/void setDesiredSSID(const char *iface, char *str) {	setStr(iface, WI_RID_DESIRED_SSID, str);}/*!	\fn void getDesiredSSID(const char *iface, char *str, int *len) 	\brief Gets the desired SSID as set on the interface 	\param iface The name of the interface	\param str Pointer to allocated memory large enough to contain the SSID string	\param len Pointer to an integer	\note This function calls the getStr function, and thus uses SIOCGWAVELAN	When this function exits, the memory at str is filled with the desired SSID string, and the integer pointed to by len is set to the length of this SSID string*/void getDesiredSSID(const char *iface, char *str, int *len) {	struct wi_req wreq;	bzero((char *)&wreq, sizeof(wreq));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_DESIRED_SSID;        getVal(iface, &wreq);	*len = (int) wreq.wi_val[0];	bzero(str, IF_SSIDLEN);	bcopy((char *)&wreq.wi_val[1], str, *len);}/*!	\fn void setOwnSSID(const char *iface, char *str) 	\brief Sets the SSID for IBSS (HostAP) creation of the interface to the specified value  	\param iface The name of the interface	\param str The string (null-terminated) value that the SSID should be set to	\note This function calls the setStr function, and thus uses SIOCSWAVELAN*/void setOwnSSID(const char *iface, char *str) {	setStr(iface, WI_RID_OWN_SSID, str);}/*!	\fn void getOwnSSID(const char *iface, char *str, int *len) 	\brief Gets the SSID for IBSS (HostAP) creation as set on the interface 	\param iface The name of the interface	\param str Pointer to allocated memory large enough to contain the SSID string	\param len Pointer to an integer	\note This function calls the getStr function, and thus uses SIOCGWAVELAN	When this function exits, the memory at str is filled with the SSID for IBSS creation string, and the integer pointed to by len is set to the length of this SSID string*/void getOwnSSID(const char *iface, char *str, int *len) {        struct wi_req wreq;        bzero((char *)&wreq, sizeof(wreq));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_OWN_SSID;        getVal(iface, &wreq);        *len = (int) wreq.wi_val[0];        bzero(str, IF_SSIDLEN);        bcopy((char *)&wreq.wi_val[1], str, *len);}/*!	\fn void getCurrentBSSID(const char *iface, char *str, int *len) 	\brief Gets the desired SSID as set on the interface 	\param iface The name of the interface	\param str Pointer to allocated memory large enough to contain the BSSID string (6 bytes)	\param len Pointer to an integer	\note Obviously, there's no such function as setCurrentBSSID. The interface should set the desired SSID it wishes to associate with. If this is succesful, then current BSSID will be set by the interface.		If the interface is in BSS (client) mode, then the current BSSID is the MAC address of the AP it is associated with. If the interface has no association, special value 44:44:44:44:44:44 is used to specify not-associated. If the interface is in HostAP mode, the current BSSID corresponds to it's own MAC address.		When this function exits, the memory at str is filled with the current BSSID string, and the integer pointed to by len is set to the length of this BSSID string (this is probably always 6)*/void getCurrentBSSID(const char *iface, char *str, int *len) {	struct wi_req wreq;	bzero((char *)&wreq, sizeof(wreq));        wreq.wi_len = WI_MAX_DATALEN;        wreq.wi_type = WI_RID_CURRENT_BSSID;        getVal(iface, &wreq);        *len = (int) wreq.wi_len - 1;	// one word is used for the size of wi_req::wi_type	*len <<= 1;	// multiply by two to get number of bytes        if (*len != 6)		errx(1, "BSSID should be of size 6 (bytes), not %d\n", *len);	bzero(str, 6);        bcopy((char *)&wreq.wi_val, str, 6);}/*!	\fn void setRTSThreshold(const char *iface, int val) 	\brief Uses setWord to set the RTS threshold. 	\param iface The name of the interface	\param val The value that the threshold should be set to	\warning The range for the threshold is 0..2347		If a frame should be sent by the interface, and it's number of bytes exceeds this threshold than	an RTS / CTS 'handshake' is performed.*/int setRTSThreshold(const char *iface, int val) {	setWord(iface, WI_RID_RTS_THRESH, val);}/*!	\fn void getRTSThreshold(const char *iface) 	\brief Uses getWord to get the RTS threshold. 	\param iface The name of the interface	\return The RTS threshold of the specified interface		If a frame should be sent by the interface, and it's number of bytes exceeds this threshold than	an RTS / CTS 'handshake' is performed.*/int getRTSThreshold(const char *iface) {	return getWord(iface, WI_RID_RTS_THRESH);}/*!	\fn void setPortType(const char *iface, int val) 	\brief Uses setWord to set the port type. 	\param iface The name of the interface	\param val The port type this interface should be set to		The port type is also called (operational) mode.\n	1 = BSS (client)\n	2 = semi ad-hoc, obsolete\n	3 = ad-hoc\n	4 = IBSS master (ad-hoc)\n	5 = unspecified\n	6 = HostAP\n	It is recommended only modes 1, 3 and 6 are used.*/int setPortType(const char *iface, int val) {	setWord(iface, WI_RID_PORTTYPE, val);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -