📄 176.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>123</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="155.htm">上一层</a>][<a href="177.htm">下一篇</a>]
<hr><p align="left"><small>发信人: digger (欧阳疯), 信区: Socket <br>
标 题: RAW sockets example code: ip_gen.c <br>
发信站: 华南网木棉站 (Wed Aug 5 19:56:05 1998), 转信 <br>
<br>
/* RAW socket utility routine: <br>
* <br>
* Write out an IP header. <br>
* shadows@whitefang.com <br>
* Thamer Al-Herbish <br>
*/ <br>
<br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
<br>
#include <sys/types.h> <br>
#include <sys/socket.h> <br>
<br>
#include <netinet/in.h> <br>
#include <arpa/inet.h> <br>
<br>
#include <netinet/in_systm.h> <br>
#include <netinet/ip.h> <br>
<br>
<br>
#include <unistd.h> <br>
#include <string.h> <br>
<br>
#if !defined(HAVE_INCKSUM) <br>
#include <checksum.h> <br>
#endif <br>
<br>
#if !defined(IPVERSION) <br>
#define IPVERSION 4 /* Incase some system does not have this definition. */ <br>
#endif /* We'll always be using 4 as the version anyway. */ <br>
<br>
<br>
#define DEFAULT_TTL 60 /* Just hard code the ttl in the ip header.*/ <br>
<br>
void ip_gen(char *packet,unsigned char protocol,struct in_addr saddr, <br>
struct in_addr daddr,unsigned short length) <br>
{ <br>
#if !defined(LINUX) <br>
struct ip *iphdr; <br>
#else <br>
struct iphdr *iphdr; <br>
#endif /* LINUX */ <br>
<br>
#if !defined(LINUX) <br>
iphdr = (struct ip *)packet; <br>
memset((char *)iphdr,'\0',sizeof(struct ip)); <br>
<br>
iphdr->ip_hl = 5; <br>
iphdr->ip_v = IPVERSION; <br>
<br>
#ifdef IP_LEN_HORDER <br>
iphdr->ip_len = length; <br>
#else <br>
iphdr->ip_len = htons(length); <br>
#endif /* IP_LEN_HORDER */ <br>
<br>
iphdr->ip_id = htons(getpid()); <br>
iphdr->ip_ttl = DEFAULT_TTL; <br>
iphdr->ip_p = protocol; <br>
<br>
iphdr->ip_src = saddr; <br>
iphdr->ip_dst = daddr; <br>
<br>
iphdr->ip_sum = in_cksum((unsigned short *)iphdr,sizeof(struct ip)); <br>
<br>
#else /* LINUX */ <br>
<br>
iphdr = (struct iphdr *)packet; <br>
memset((char *)iphdr,'\0',sizeof(struct iphdr)); <br>
<br>
iphdr->ihl = 5; <br>
iphdr->version = IPVERSION; <br>
<br>
#ifdef IP_LEN_HORDER <br>
iphdr->tot_len = length; <br>
#else <br>
iphdr->tot_len = htons(length); <br>
#endif /* IP_LEN_HORDER */ <br>
<br>
iphdr->id = htons(getpid()); <br>
iphdr->ttl = DEFAULT_TTL; <br>
iphdr->protocol = protocol; <br>
<br>
iphdr->saddr = saddr.s_addr; <br>
iphdr->daddr = daddr.s_addr; <br>
<br>
iphdr->check = in_cksum((unsigned short *)iphdr,sizeof(struct iphdr)); <br>
#endif /* LINUX */ <br>
return; <br>
} <br>
<br>
-- <br>
#################### <br>
# 遥 眺 淑 女 # <br>
####################################### <br>
# 君 子 好 球 # <br>
#################### <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="155.htm">上一层</a>][<a href="177.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 + -