📄 monitor_api.c
字号:
/* $Id: monitor_api.c,v 1.16 2001/09/29 16:06:39 jm Exp $ * API calls for Monitor module * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2000, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#include <string.h>#include "monitor.h"#include "agentapi.h"#include "dyn_api.h"#include "dyn_wireless.h"#include "debug.h"#include "util.h"#include "mn.h" /* MAX_INTERFACES */#include "owntypes.h"#define DEBUG_FLAG 'm' /* same as in monitor.c */extern struct monitor_global_data mon_conf;extern struct monitor_interface mon_devs[MAX_INTERFACES];extern struct monitor_conf_vars monitor_conf[];int monitor_api_get_ch(unsigned char *buffer, __u16 *length){ int ch, len, count = 0, i; struct dynamics_mn_iw_ch_info *info = (struct dynamics_mn_iw_ch_info *)buffer; len = sizeof(struct dynamics_mn_iw_ch_info); for (i = 0; i < MAX_INTERFACES; i++) { if (!mon_devs[i].in_use) continue; /* get channel */ ch = dyn_wireless_get_channel(mon_devs[i].sock, mon_devs[i].ifname); if (ch < 0) { DEBUG(DEBUG_FLAG, "monitor_api_get_ch: channel " "< 0 (%s)\n", mon_devs[i].ifname); continue; } mon_devs[i].channel = ch; /* if changed */ /* copy to caller */ if (*length+len > API_DATA_SIZE) { DEBUG(DEBUG_FLAG, "monitor_api_get_ch: Not enough " "room for interface name (%d, %d)\n", *length, *length+len); return 1; } memcpy(info[count].ifname, mon_devs[i].ifname, IFNAMSIZ); info[count].channel = mon_devs[i].channel; /* get AP hw addr */ if (dyn_wireless_get_ap_address(mon_devs[i].sock, mon_devs[i].ifname, info[count].ap_hwaddr) < 0) { DEBUG(DEBUG_FLAG, "monitor_api_get_ch: get AP hw " "addr failed\n"); continue; } *length += len; DEBUG(DEBUG_FLAG, "monitor_api_get_ch: %s: %d - %s\n", info[count].ifname, info[count].channel, ether_hwtoa(info[count].ap_hwaddr)); } return 0;}int monitor_api_set_ch(char *ifname, int channel){ int r, i; for (i = 0; i < MAX_INTERFACES; i++) { if (!mon_devs[i].in_use || memcmp(ifname, mon_devs[i].ifname, strlen(ifname))) continue; /* set channel */ r = dyn_wireless_set_channel(mon_devs[i].sock, mon_devs[i].ifname, channel); return r; } DEBUG(DEBUG_FLAG, "monitor_set_ch: not wireless interface (%s)\n", ifname); return -1;}static char *itoa(int i){ static char str[20]; snprintf(str, 19, "%d", i); return str;}static int get_mon_conf(char *buffer, int len){ int curr = 0, r = 0, i; struct monitor_conf_vars *t = monitor_conf; for (i = 0, r = 0; t[i].value != NULL && r == 0; i++) r = copy_str(buffer, len, &curr, t[i].name, itoa(*(t[i].value))); if (r) { DEBUG(DEBUG_FLAG, "get_mon_conf: insufficient space\n"); return API_INSUFFICIENT_SPACE; } DEBUG(DEBUG_FLAG, buffer); return API_SUCCESS;}static int get_mon_conf_var(char *buffer, int length){ int curr = 0, r, i = 0, len; struct dynamics_mn_mon_conf_var *reply = (struct dynamics_mn_mon_conf_var *)buffer; struct monitor_conf_vars *t = monitor_conf; len = strlen(reply->name) < MAX_MON_CONF_VAR_LEN ? strlen(reply->name) : MAX_MON_CONF_VAR_LEN; while (t[i].value != NULL) { r = strncasecmp(reply->name, t[i].name, len); if (t[i].min_chars > len && r == 0) return API_ILLEGAL_PARAMETERS; if (r == 0) break; /* found variable */ i++; } if (t[i].value == NULL) { DEBUG(DEBUG_FLAG, "mon_conf_get_var: unknown variable\n"); return API_NOT_AVAILABLE; } r = copy_str(buffer, length, &curr, t[i].name, itoa(*(t[i].value))); if (r) { DEBUG(DEBUG_FLAG, "mon_conf_get_var: insufficient space\n"); return API_INSUFFICIENT_SPACE; } DEBUG(DEBUG_FLAG, buffer); return API_SUCCESS;}static int set_mon_conf_var(char *buffer, int length){ int i = 0, len = 0, r; struct dynamics_mn_mon_conf_var *reply = (struct dynamics_mn_mon_conf_var *)buffer; struct monitor_conf_vars *t = monitor_conf; len = strlen(reply->name) < MAX_MON_CONF_VAR_LEN ? strlen(reply->name) : MAX_MON_CONF_VAR_LEN; DEBUG(DEBUG_FLAG, "set_mon_conf_var: '%s', len %d\n", reply->name, len); while (t[i].value != NULL) { r = strncasecmp(reply->name, t[i].name, len); if (t[i].min_chars > len && r == 0) return API_ILLEGAL_PARAMETERS; if (r == 0) break; /* found variable */ i++; } if (t[i].value == NULL) { DEBUG(DEBUG_FLAG, "set_mon_conf_var: unknown variable\n"); return API_NOT_AVAILABLE; } if ((reply->value >= t[i].min || t[i].min == -1) && (reply->value <= t[i].max || t[i].max == -1)) { *(t[i].value) = reply->value; return API_SUCCESS; } DEBUG(DEBUG_FLAG, "set_mon_conf_var: illegal value for " "var %s\n (%d - %d)", reply->name, t[i].min, t[i].max); return API_ILLEGAL_PARAMETERS;}int monitor_api_mon_conf(char *buffer, int len, int type){ switch (type) { case GET_MONCONF: DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: get_mon_conf\n"); return get_mon_conf(buffer, len); case GET_MONCONF_VAR: DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: get_mon_conf_var\n"); return get_mon_conf_var(buffer, len); case SET_MONCONF_VAR: DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: set_mon_conf_var\n"); return set_mon_conf_var(buffer, len); default: DEBUG(DEBUG_FLAG, "monitor_api_mon_conf: unknown type\n"); return API_UNDEFINED; } /* never reached */ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -