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

📄 monitor_util.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: monitor_util.c,v 1.13 2001/09/29 16:06:39 jm Exp $ * Monitor utilities 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 <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <string.h>#include <stddef.h>#include "monitor.h"#include "debug.h"#include "mn.h" /* MAX_INTERFACES */#define DEBUG_FLAG 'm' /* same as in monitor.c */extern struct monitor_global_data mon_conf;extern struct monitor_interface mon_devs[MAX_INTERFACES];int next(int p){	assert(p >= 0);	if (p == 9)		return 0;	return p + 1;}int prev(int p){	assert(p >= 0);	if (p == 0)		return 9;	return p - 1;}/* return: *   <0  worst happens to be the current FA :( *   >0  the released slot */int drop_worst(struct timeval *tstamp, struct monitor_interface *dev){	int worst_avg = 1000; /* theoretical max quality is below */	int worst_index = -2, i;	/* (POLICY) */	/* Find old entries */	for (i = 0; i < MAX_MONITOR; i++) {		/* old ghost. If MAX_TIME has passed		 * for this entry and it still doesn't		 * have decent values, just drop it */		if (dev->mon[i].added.tv_sec + 		    mon_conf.worst_max_time < tstamp->tv_sec &&		    dev->mon[i].avg == 0)			return i;	}	/* No old entries found. Find the worst entry */	for (i = 0; i < MAX_MONITOR; i++) {		if ((dev->mon[i].added.tv_sec + 		     mon_conf.worst_min_time) > tstamp->tv_sec)			return -1; /* new entry. Don't update faster than				    * in MIN_TIME interval */		if (dev->mon[i].avg < worst_avg) {			worst_avg = dev->mon[i].avg;			worst_index = i;		}	}	if (worst_index >= 0 && worst_index != mon_conf.current_fa)		return worst_index;	/* worst one is current FA :( */	return -1;}int get_free_slot(struct timeval *tstamp, struct monitor_interface *dev){	int i, ph;	for (i = 0; i < MAX_MONITOR; i++) {		if (dev->mon[i].active != 1)			return i;	}	/* no non-active entries found */	ph = drop_worst(tstamp, dev);	if (ph < 0) {		DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, "		      "worst entry just changed. Not dropped.\n");		return -1;	}	DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, "	      "worst entry dropped (%s).\n",	      inet_ntoa(dev->mon[ph].adv->addr));	return ph;}struct monitor_interface *monitor_get_dev(char *ifname){	int i;	DEBUG(DEBUG_FLAG, "monitor_get_dev: %s (len %d), interfaces %d\n",	      ifname, strlen(ifname), mon_conf.interfaces);	if (ifname == NULL) {		DEBUG(DEBUG_FLAG, "monitor_get_dev: ifname == NULL!\n");		return NULL;	}	for(i = 0; i< MAX_INTERFACES; i++) {		if (mon_devs[i].in_use && 		    !strncmp(ifname, mon_devs[i].ifname, IFNAMSIZ)) {			return &mon_devs[i];		}	}	DEBUG(DEBUG_FLAG, "monitor_get_dev: interface %s not found\n",	      ifname);	return NULL;}void print_entries(void){	int i, j;	for (j = 0; j < MAX_INTERFACES; j++) {		if (!mon_devs[j].in_use)			continue;		for (i = 0; i < MAX_MONITOR; i++) {			if (mon_devs[j].mon[i].active == 1) {				DEBUG(DEBUG_FLAG, "%-15s: prio %d\n",				      inet_ntoa(mon_devs[j].mon[i].adv->addr),				      mon_devs[j].mon[i].adv->priority);			}		}	}}

⌨️ 快捷键说明

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