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

📄 autotest_fa.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: autotest_fa.c,v 1.4 2000/04/06 07:26:53 jm Exp $ * Automatic system testing data cathering using FA API * * 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. */#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif#include <stdio.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <sys/time.h>#include <string.h>#include <errno.h>#include <ctype.h>#include "dyn_falib.h"#define MN_HOME_ADDR "194.100.51.5"#define FA_COUNT 14#define FA_PATH "%i/fa_admin_socket"#define UDPPORT 10434static dyn_tunnel_id tun_id;static void reply(int s, struct sockaddr_in addr){	struct dynamics_tunnel_info tinfo;	int r, i, len;	struct in_addr fa_co_addrs[FA_COUNT];	char path[256];	printf("%s:%i\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));	memset(fa_co_addrs, 0xff, sizeof(fa_co_addrs));	for (i = 1; i <= FA_COUNT; i++) {		/* printf("FA%i: ", i); */		snprintf(path, sizeof(path), FA_PATH, i);		r = dynamics_fa_init(path);		if (r != API_SUCCESS) {			printf("dynamics_fa_init failed for %s\n", path);			continue;		}		len = sizeof(struct dynamics_tunnel_info);		r = dynamics_fa_get_tunnel_info(tun_id, &tinfo, &len, 1);		if (r == API_SUCCESS) {#if 0			printf("%s ", inet_ntoa(tinfo.mn_addr));			printf("%s ", inet_ntoa(tinfo.co_addr));			printf("%s ", inet_ntoa(tinfo.ha_addr));			printf("conf=%i spi=%i\n", tinfo.confirmed, tinfo.spi);#endif			fa_co_addrs[i-1].s_addr = tinfo.co_addr.s_addr;		}	}	r = sendto(s, fa_co_addrs, sizeof(fa_co_addrs), 0,		   (struct sockaddr *) &addr, sizeof(addr));	if (r < 0)		perror("sendto");	else if (r != sizeof(fa_co_addrs))		printf("sent only %i/%i bytes\n", r, sizeof(fa_co_addrs));}int main(void){	char buf[3];	int s, n;	struct sockaddr_in addr;	unsigned int len;	inet_aton(MN_HOME_ADDR, &tun_id.mn_addr);	tun_id.ha_addr.s_addr = 0;	s = socket(AF_INET, SOCK_DGRAM, 0);	if (s < 0) {		perror("socket");		exit(1);	}	memset((char *) &addr, 0, sizeof(addr));	addr.sin_family = AF_INET;	addr.sin_addr.s_addr = INADDR_ANY;	addr.sin_port = htons(UDPPORT);	if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {		perror("bind");		exit(1);	}	for (;;) {		len = sizeof(addr);		n = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &addr,			     &len);		if (n < 0) {			perror("recvfrom");			continue;		}		if (n < 2 || buf[0] != 'C' || buf[1] != 'O')			continue;		reply(s, addr);	}	return 0;}

⌨️ 快捷键说明

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