📄 299.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://apue.dhs.org"><font face="黑体"><big><big>apue</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> ● UNIX网络编程 (BM: clown) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="index.htm">回到开始</a>][<a href="289.htm">上一层</a>][<a href="300.htm">下一篇</a>]
<hr><p align="left"><small>发信人: lisuke (smart), 信区: Security <br>
标 题: 一个简单的telnetd防护程序(2)[Z] <br>
发信站: BBS 水木清华站 (Wed Oct 25 00:27:02 2000) <br>
<br>
防火墙模块:ipauth.c <br>
/************************************************************************/ <br>
/* ipauth.c, by digger */ <br>
/* ipauth read the file that include all IPs that authorized to access */ <br>
/* some services of localhost, the format is just like: */ <br>
/************************************************************************/ <br>
/* # this is one comments line begin with "#" */ <br>
/* 172.18.85.0 # allow subnet <br>
/* 172.18.86.146 */ <br>
/* 172.18.86.145 */ <br>
/* ... */ <br>
/************************************************************************/ <br>
/* function InitAuthIP read the authorized IP into memory array, and */ <br>
/* function IPIsAuthed check if the given IP is authorized */ <br>
/************************************************************************/ <br>
# include <stdio.h> <br>
# include <sys/types.h> <br>
# include <string.h> <br>
# include <sys/socket.h> <br>
# include <netinet/in.h> <br>
# include <arpa/inet.h> <br>
# define MAXHOSTS 32 <br>
# define TRUE 0 <br>
# define FALSE -1 <br>
u_long AuthedIP[MAXHOSTS]; /* authorized IPs */ <br>
int AuthedIPNum; /* number of authorized IPs */ <br>
void InitAuthIP(char *file) /* read IP from file into memory array */ <br>
{ <br>
FILE *fp; <br>
char sBuf[64]; <br>
char *tmp; <br>
char *s; <br>
u_long IP; <br>
if ((fp = fopen(file,"r")) == NULL) { <br>
fprintf(stderr, "fopen %s error, terminated\n", file); <br>
exit(-1); <br>
} <br>
AuthedIPNum = 0; <br>
while (AuthedIPNum < MAXHOSTS && !feof(fp) && fgets(sBuf, 64, fp)) { <br>
tmp = sBuf; <br>
s = strtok(tmp, " \t\r\n"); <br>
if (s == NULL) continue; /* ignore empty line */ <br>
if (s[0] == '#') continue; /* ignore commits line */ <br>
if ((IP = inet_addr(s)) != -1) { <br>
AuthedIP[AuthedIPNum ++] = IP; <br>
} <br>
} <br>
if (AuthedIPNum == 0) { /* default Authorized IP */ <br>
AuthedIP[0] = inet_addr("127.0.0.1"); <br>
AuthedIPNum ++ ; <br>
} <br>
fclose(fp); <br>
} <br>
int IPIsAuthed(u_long IP) <br>
AuthedIP[0] = inet_addr("127.0.0.1"); <br>
AuthedIPNum ++ ; <br>
} <br>
fclose(fp); <br>
} <br>
{nt IPIsAuthed(u_long IP) <br>
int i; <br>
for (i = 0;i < AuthedIPNum;i ++) { <br>
if ((AuthedIP[i] & (u_long)255) == 0) { /* subnet */ <br>
if ((AuthedIP[i] & IP) == AuthedIP[i]) <br>
break; <br>
} else if (AuthedIP[i] == IP) { /* ip */ <br>
break; <br>
} <br>
} <br>
if (i == AuthedIPNum) return FALSE; <br>
else return TRUE; <br>
} <br>
-- <br>
<br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="289.htm">上一层</a>][<a href="300.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -