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

📄 main.c

📁 Adhoc无线网络路由协议源码
💻 C
字号:
/* * Copyright (C) 2002, YONGGUANG ZHANG (HRL LABS) */#include <stdio.h>#include <stdlib.h>#include <search.h>#include <errno.h>#include <unistd.h>#include <string.h>#include <netinet/in.h>#include <sys/socket.h>#include <sys/wait.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/stat.h>#include <net/if.h>#include <arpa/inet.h>#include <linux/netfilter.h>#include <linux/if_tun.h>#include <signal.h>#include <assert.h>#include <fcntl.h>#include <net/route.h>#include <time.h>#define BUFSIZE 2048#define TUN_DEV_IP "127.0.0.2"	/* ip address for the tun device *//* demo main function */main(){	int fi, fo;	fi = tun_init();	fo = rawsock_init();	if (!fi || !fo) {		exit(1);	}	printf("ready!\n");	for (;;) {		u_char buf[BUFSIZE];		char cmd[64];		int len;		len = tun_in(fi, buf);		sleep(2);		sprintf(cmd, "route del %d.%d.%d.%d",			buf[16],buf[17],buf[18],buf[19]);		fprintf(stderr, "%s\n", cmd);		system(cmd);		system("route add -host 10.0.0.12 gw 10.0.0.49 dev eth1");		sleep(2);		// test output from this host		rawsock_out(fo, buf,len);		// test output from a different host (forwarding)		// flip the source addr yet maintain the checksum		{ u_char x = buf[15]; buf[15]=buf[13]; buf[13]=x; }		rawsock_out(fo, buf,len);	}}

⌨️ 快捷键说明

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