icmp_input.c

来自「一款类linux的操作系统源码」· C语言 代码 · 共 83 行

C
83
字号
/* *  Roadrunner/pk *    Copyright (C) 1989-2002  Cornfed Systems, Inc. * *  The Roadrunner/pk operating system is free software; you can *  redistribute and/or modify it under the terms of the GNU General *  Public License, version 2, as published by the Free Software *  Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public *  License along with this program; if not, write to the Free *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *  MA 02111-1307 USA * *  More information about the Roadrunner/pk operating system of *  which this file is a part is available on the World-Wide Web *  at: http://www.cornfed.com. * */#include <net/ether.h>#include <net/icmp.h>#include <net/ip.h>#include <net/netif.h>#if _DEBUG_ICMP#include <stdio.h>#endif#include <string.h>u_short cksum(void *buf, int len);voidicmp_input(buf_t b){    etherhdr_t eh = (etherhdr_t) bstart(b);    iphdr_t ih = (iphdr_t) eh->data;    icmphdr_t ich = (icmphdr_t) (eh->data + IP_HLEN(ih));    if (ich->type == ICMP_ECHO_REQUEST) {	ipaddr ip;	int len;	/* Format and send an ICMP echo reply */	ich->type = ICMP_ECHO_REPLY;	ip = ih->dst;	ih->dst = ih->src;	ih->src = ip;	bcopy(eh->src, eh->dst, ETHER_ADDR_LEN);	ich->cksum = 0;	len = NET2HS(ih->len) - IP_HLEN(ih);	ich->cksum = cksum(ich, len);	netif_send(b);	return;    }#if _DEBUG_ICMP    switch (ich->type) {    case ICMP_ECHO_REPLY:	kprintf("icmp_input: echo reply\n");	break;    case ICMP_DEST_UNREACH:	kprintf("icmp_input: destination unreachable\n");	break;    case ICMP_REDIRECT:	kprintf("icmp_input: redirect\n");	break;    case ICMP_TIMESTAMP_REQUEST:	kprintf("icmp_input: timestamp request\n");	break;    case ICMP_TIMESTAMP_REPLY:	kprintf("icmp_input: timestamp reply\n");	break;    default:	kprintf("icmp_input: unsupported type (%02x)\n", ich->type);    }#endif    brel(b);}

⌨️ 快捷键说明

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