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

📄 arp_input.c

📁 一款类linux的操作系统源码
💻 C
字号:
/* *  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/arp.h>#include <net/netif.h>#if _DEBUG_ARP#include <stdio.h>#endif#include <stdlib.h>#include <string.h>#include <sys/intr.h>voidarp_input(buf_t b){    etherhdr_t eh = (etherhdr_t) bstart(b);    arphdr_t ah = (arphdr_t) eh->data;    arpentry_t ae;    ah->hwtype = NET2HS(ah->hwtype);    ah->prtype = NET2HS(ah->prtype);    if (ah->hwtype != ARP_HW_ETHERNET || ah->prtype != ETHER_TYPE_IP ||	ah->hwlen != ETHER_ADDR_LEN || ah->prlen != sizeof(ipaddr)) {	brel(b);	return;    }    switch (NET2HS(ah->op)) {    case ARP_OP_REQUEST:#if _DEBUG_ARP	{	    ipaddr ip1, ip2;	    char s1[32], s2[32];	    ip1 = NET2HL(ah->tpa);	    ip2 = NET2HL(ah->spa);	    kprintf("arp_input: who has %s tell %s\n",		    ip2str(ip1, s1), ip2str(ip2, s2));	}#endif	ah->tpa = NET2HL(ah->tpa);	ae = arp_find(ah->tpa);	if (ae == NULL) {	    brel(b);	    return;	}	/* Format and send an ARP reply */	ah->hwtype = HS2NET(ah->hwtype);	ah->prtype = HS2NET(ah->prtype);	ah->op = HS2NET(ARP_OP_REPLY);	ah->tpa = ah->spa;	ah->spa = HL2NET(netif_primary.ip);	bcopy(ah->sha, ah->tha, ETHER_ADDR_LEN);	bcopy(ah->tha, eh->dst, ETHER_ADDR_LEN);	bcopy(netif_primary.hwaddr, ah->sha, ETHER_ADDR_LEN);	netif_send(b);	break;    case ARP_OP_REPLY:	ah->spa = NET2HL(ah->spa);	ae = arp_find(ah->spa);	if (ae != NULL && ae->state == ARP_ENTRY_PENDING) {#if _DEBUG_ARP	    {		char s1[20], s2[20];		ip2str(ah->spa, s1);		ether2str(ah->sha, s2);		kprintf("arp_input: %s is at %s\n", s1, s2);	    }#endif	    /* Update ARP entry */	    bcopy(ah->sha, ae->hwaddr, ETHER_ADDR_LEN);	    ae->state = ARP_ENTRY_RESOLVED;	    ae->ttl = ARP_TTL_RESOLVED;	    /* Send any queued packets */	    brel(b);	    for (;;) {		disable;		b = bdeq(&(ae->pktq));		enable;		if (b == NULL)		    break;		eh = (etherhdr_t) bstart(b);		bcopy(ae->hwaddr, eh->dst, ETHER_ADDR_LEN);		netif_send(b);	    }	} else	    brel(b);	break;    default:#if _DEBUG_ARP	kprintf("arp_input: unsupported opcode (%04x)\n", NET2HS(ah->op));#endif	brel(b);    }}

⌨️ 快捷键说明

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