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

📄 fahtml.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: fahtml.c,v 1.3 2001/07/11 15:12:45 jm Exp $ * Statistics information of FA in HTML format to stdout * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2001, 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. */#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif#include <stdio.h>#include <stdlib.h>#include <sys/socket.h>#include <sys/param.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <string.h>#include <errno.h>#include <time.h>#include <signal.h>#include <getopt.h>#include "util.h"#include "dyn_falib.h"static char *default_path = "/var/run/dynamics_fa_read";#define MAX_TUNNELS 128#define PID_FILE "/var/run/fastatus.pid"static void handle_request(){	struct dynamics_tunnel_info tinfo;	struct dynamics_fa_status status;	dyn_tunnel_id tunnels[MAX_TUNNELS];	int r, c, i, len;	char mnaddr[64], haaddr[64];	r = dynamics_fa_get_status(&status, 1);	if (r != API_SUCCESS) {		printf("API call failed\n");		return;	}	printf("<BIG>Dynamics Foreign Agent</BIG>\n"	       "version %s\n<P>\n", status.version);	printf("<TABLE BORDER=1>\n"	       "<TR><TH>MN addr<TH>care-of addr<TH>HA addr"	       "<TH>created<TH>expires<TH>SPI<TH>conf.\n");	c = MAX_TUNNELS;	r = dynamics_fa_get_tunnels(&c, tunnels, 1);	if (r != API_SUCCESS) {		printf("error=%i\n", r);		return;	}	for (i = 0; i < c; i++) {		len = sizeof(tinfo);		r = dynamics_fa_get_tunnel_info(tunnels[i], &tinfo, &len, 1);		if (r != API_SUCCESS || len != sizeof(tinfo)) {			printf("API call failed\n");			continue;		}		snprintf(mnaddr, sizeof(mnaddr), "%s",			 inet_ntoa(tinfo.mn_addr));		snprintf(haaddr, sizeof(haaddr), "%s",			 inet_ntoa(tinfo.ha_addr));		printf("<TR><TD><A HREF=\"user.php?mn=%s&ha=%s\">%s</A>\n",		       mnaddr, haaddr, mnaddr);		printf("<TD>%s\n",		       inet_ntoa(tinfo.co_addr));		printf("<TD>%s\n", haaddr);		printf("<TD><SMALL>%s</SMALL>",		       ctime(&tinfo.creation_time));		printf("<TD><SMALL>%s</SMALL>",		       ctime(&tinfo.expiration_time));		printf("<TD>%i<TD>%i\n",		       tinfo.spi, tinfo.confirmed);	}	printf("</TABLE><P>\n");	printf("<TABLE BORDER=1><TR><TD>"	       "current tunnels %i\n<TD>requests accepted %li"	       "\n"	       "<TR><TD>advertisements sent %li<TD>requests rejected %li"	       "</TABLE><P>\n",	       status.tunnel_count, status.req_accepted,	       status.adv_sent, status.req_rejected);}int main(int argc, char *argv[]){	char *path = NULL;	int c;	while (1) {		int option_index = 0;		static struct option long_options[] = {			{0, 0, 0, 0}		};				c = getopt_long (argc, argv, "s:",				 long_options, &option_index);		if (c == -1)			break;				switch (c) {		case 's':			path = malloc(MAXPATHLEN);			if (path == NULL) {				fprintf(stderr, "malloc for path: %s\n",					strerror(errno));				exit(1);			}			dynamics_strlcpy(path, optarg, MAXPATHLEN);			break;		case '?':			fprintf(stderr, "fahtml -s [API socket]\n");			exit(1);		default:			printf ("?? getopt returned character code "				"0%o ??\n", c);		}	}	if (path == NULL)		path = default_path;	if (dynamics_fa_init(path) != API_SUCCESS) {		fprintf(stderr, "API initialization failed\n");		exit(1);	}	handle_request();	return 0;}

⌨️ 快捷键说明

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