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

📄 proc_v4.c

📁 unix网络编程第一卷socket编程书上的全部源代码
💻 C
字号:
#include	"ping.h"voidproc_v4(char *ptr, ssize_t len, struct msghdr *msg, struct timeval *tvrecv){	int				hlen1, icmplen;	double			rtt;	struct ip		*ip;	struct icmp		*icmp;	struct timeval	*tvsend;	ip = (struct ip *) ptr;		/* start of IP header */	hlen1 = ip->ip_hl << 2;		/* length of IP header */	if (ip->ip_p != IPPROTO_ICMP)		return;				/* not ICMP */	icmp = (struct icmp *) (ptr + hlen1);	/* start of ICMP header */	if ( (icmplen = len - hlen1) < 8)		return;				/* malformed packet */	if (icmp->icmp_type == ICMP_ECHOREPLY) {		if (icmp->icmp_id != pid)			return;			/* not a response to our ECHO_REQUEST */		if (icmplen < 16)			return;			/* not enough data to use */		tvsend = (struct timeval *) icmp->icmp_data;		tv_sub(tvrecv, tvsend);		rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;		printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",				icmplen, Sock_ntop_host(pr->sarecv, pr->salen),				icmp->icmp_seq, ip->ip_ttl, rtt);	} else if (verbose) {		printf("  %d bytes from %s: type = %d, code = %d\n",				icmplen, Sock_ntop_host(pr->sarecv, pr->salen),				icmp->icmp_type, icmp->icmp_code);	}}

⌨️ 快捷键说明

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