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

📄 dyn_halib.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: dyn_halib.c,v 1.10 2000/11/04 17:07:55 jm Exp $ * Dynamics Home Agent API support library implementation * * 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 <sys/types.h>#include <unistd.h>#include <string.h>#include "lib_api.h"#include "dyn_halib.h"#define TMP_PREFIX   "halib"#define TMP_DIR       NULL#define SOCK_PERM     0600#define MIN(x,y) (((x) < (y)) ? (x) : (y))#define DEFAULT_PATH  "/var/run/dynamics_ha_admin"/* * Initialize library * Parameters: *   agent - path to mobility agent * Returns: *  API_FAILED - error in intialization *  API_SUCCESS - success *    */int dynamics_ha_init(char *agent){  	if (agent != NULL) 		return lib_init(agent, TMP_DIR, TMP_PREFIX, SOCK_PERM);	else return lib_init(DEFAULT_PATH, TMP_DIR, TMP_PREFIX, SOCK_PERM);}int dynamics_ha_get_tunnels(int *tunnel_count, dyn_tunnel_id *data,			    int timeout){	int r;	struct api_msg msg;	if (tunnel_count == NULL ||	    *tunnel_count <= 0 ||	    data == NULL ||	    timeout < -1)		return API_ILLEGAL_PARAMETERS;	r = perform_call(API_GET_TUNNELS, NULL, 0, timeout, &msg);  	if (r != API_SUCCESS) return r;	r = MIN(msg.length / sizeof(dyn_tunnel_id), *tunnel_count);	*tunnel_count = msg.length / sizeof(dyn_tunnel_id);	memcpy(data, msg.params, r * sizeof(dyn_tunnel_id));	return (r == *tunnel_count)? API_SUCCESS : API_INSUFFICIENT_SPACE;  }int dynamics_ha_get_tunnel_info(dyn_tunnel_id id, 				struct dynamics_tunnel_info *data, 				int *size_of_data, int timeout){	int r;	struct api_msg msg;	if (data == NULL ||	    size_of_data == NULL ||	    *size_of_data <= 0 ||	    timeout < -1)		return API_ILLEGAL_PARAMETERS;  	r = perform_call(API_GET_TUNNEL_INFO, &id, sizeof(dyn_tunnel_id), 			 timeout, &msg);  	if (r != API_SUCCESS) return r;	r = MIN(*size_of_data, msg.length);  	memcpy(data, msg.params, r);	*size_of_data = msg.length;	return API_SUCCESS;  }int dynamics_ha_destroy_tunnel(dyn_tunnel_id id, int timeout){	int r;	struct api_msg msg;	if (timeout < -1) 		return API_ILLEGAL_PARAMETERS;	r = perform_call(API_DESTROY_TUNNEL, &id, 			 sizeof(dyn_tunnel_id), timeout, &msg);  	return r;}int dynamics_ha_get_status(struct dynamics_ha_status *status, int timeout){	int r;	struct api_msg msg;	/* check parameters */	if (status == NULL || timeout < -1)		return API_ILLEGAL_PARAMETERS;	/* do the call */	r = perform_call(API_GET_STATUS, NULL, 0, timeout, &msg);	if (r != API_SUCCESS) return r;	if (msg.length != sizeof(struct dynamics_ha_status))		return API_FAILED;	memcpy(status, msg.params, msg.length); 	return API_SUCCESS;}int dynamics_ha_get_care_of_addr(struct in_addr mobile_addr, 				 struct in_addr * care_of_addr, int timeout) {	int r;	struct api_msg msg;	/* check parameters */	if (care_of_addr == NULL || 	    timeout < -1)		return API_ILLEGAL_PARAMETERS;	/* do the call */	r = perform_call(API_GET_CAREOF_ADDR, &mobile_addr, 			 sizeof(struct in_addr), timeout, &msg);	if (r != API_SUCCESS) return r;	if (msg.length != sizeof(struct in_addr))		return API_FAILED;	memcpy(care_of_addr, msg.params, msg.length); 	return API_SUCCESS;}int dynamics_ha_enable_mobile(struct in_addr mobile_addr, 			      int enable, int timeout){	int r;	struct api_msg msg;	if (timeout < -1) 		return API_ILLEGAL_PARAMETERS;	r = perform_call(API_ENABLE_MOBILE, &mobile_addr, 			 sizeof(struct in_addr), timeout, &msg);  	return r;}char *dynamics_ha_get_error_string(int err){	return get_error_string(err);}/* * Get current agent address */char *dynamics_ha_get_agent_path(void){	return get_agent_path();}/* * Reload Home Agent configuration */int *dynamics_reload_config(int timeout){        	int r;	struct api_msg msg;	r = perform_call(API_RELOAD_CONFIG, NULL, 0, timeout, &msg);	return API_SUCCESS;}

⌨️ 快捷键说明

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