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

📄 authorized.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: authorized.c,v 1.3 2000/04/06 07:26:52 jm Exp $ * Routines to handle authorized networks (IP addresses) * * 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 <stdio.h>#include <stdlib.h>#include <assert.h>#include "authorized.h"#include "list.h"#include "debug.h"/* defines */#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif#define DEBUG_FLAG 'A'#define ASSERT assert/* "Mxx" are test case IDs to help in the design of the test module *//* INPUT VALUES: * * M01) No input values *    ) Out of memory * *//** * authorized_init: *  * Allocate memory for the list structure and initialize the list. * * Returns: A pointer to the list, or NULL on error. */struct list *authorized_init(void){	struct list *list;	list = malloc(sizeof(struct list));	if (list == NULL) {		DEBUG(DEBUG_FLAG,		      "authorized_init: not enough memory for the list of "		      "authorized addresses\n");		return NULL;	}	list_init(list);	return list;}/* INPUT VALUES: * * M02) List is NULL * M03) List is valid *    ) Out of memory * *//** * authorized_add: * @list:  * @network:  * @netmask:  *  * Add a network (or host if netmask is 255.255.255.255) * to the list of autorized addresses. *  * Returns: TRUE if successful, else FALSE */int authorized_add(struct list *list, struct in_addr network,                   struct in_addr netmask){	struct authorized_entry *entry;	if (list == NULL) {		DEBUG(DEBUG_FLAG, "authorized_add: authorized list is NULL\n");		return FALSE;	}	entry = malloc(sizeof(struct authorized_entry));	if (entry == NULL) {		DEBUG(DEBUG_FLAG,		      "authorized_add: not enough memory for adding "		      "authorized network entry to the list\n");		return FALSE;	}	list_init_node(&entry->node);	entry->network.s_addr = network.s_addr & netmask.s_addr;	if (network.s_addr != entry->network.s_addr) {		DEBUG(DEBUG_FLAG,		      "authorized_add: warning: specified network address is "		      "not the first address of the subnet\n");	}	entry->netmask = netmask;	list_add_tail(list, &entry->node);	return TRUE;}/* INPUT VALUES: * * M04) List is NULL * M05) Entry can be found in the list * M06) Entry cannot be found in the list * *//** * authorized_check: * @list:  * @addr:  *  * Check if the address is covered by the authorized list. *  * Returns: TRUE if covered, else FALSE */int authorized_check(struct list *list, struct in_addr addr){	struct authorized_entry *entry;	if (list == NULL) {		DEBUG(DEBUG_FLAG,		      "authorized_check: authorized list is NULL\n");		return FALSE;	}	entry = (struct authorized_entry *) list_get_first(list);	while(entry != NULL) {		if ((addr.s_addr & entry->netmask.s_addr) ==		    entry->network.s_addr) {			return TRUE;		}		entry = (struct authorized_entry *)			list_get_next(&entry->node);	}	return FALSE;}/* INPUT VALUES: * * M07) List is NULL * M08) List is valid * *//** * authorized_destroy: * @list:  *  * Remove all the entries in the authorized list and * frees the memory and the list structure itself */void authorized_destroy(struct list *list){	struct authorized_entry *entry;	if (list == NULL) {		DEBUG(DEBUG_FLAG,		      "authorized_destroy: authorized list is NULL\n");		return;	}	do {		entry = (struct authorized_entry *) list_remove_first(list);		if (entry == NULL) break;		free(entry);	} while(1);	ASSERT(list_is_empty(list) == TRUE);	free(list);}

⌨️ 快捷键说明

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