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

📄 ip_send.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/ether.h>#include <net/ip.h>#include <net/netif.h>#include <stdlib.h>#include <string.h>#include <sys/intr.h>u_short cksum(void *buf, int len);//2002年09月12日增加u_short cksum(void *buf, int len){}voidip_send(buf_t b, u_short len, u_char pr, ipaddr src, ipaddr dst){    etherhdr_t eh = (etherhdr_t) bstart(b);    iphdr_t ih = (iphdr_t) eh->data;    arpentry_t ae;    /* Format and send IP packet */    ih->ver = (IP_VERSION << 4) | (sizeof(struct iphdr) >> 2);    ih->tos = 0;    ih->len = sizeof(struct iphdr) + len;    ih->id = 0;    ih->off = 0;    ih->ttl = 255;    ih->pr = pr;    ih->cksum = 0;    ih->src = src;    ih->dst = dst;    /* Convert to network order */    ih->len = HS2NET(ih->len);    ih->src = HL2NET(ih->src);    ih->dst = HL2NET(ih->dst);    /* Compute header checksum */    ih->cksum = cksum(ih, sizeof(struct iphdr));    eh->type = HS2NET(ETHER_TYPE_IP);    /* Locate an ARP entry for destination IP address in the packet */    ae = arp_find(dst);    if (ae == NULL) {	etheraddr hwaddr;	/* Setup a new ARP table entry */	bzero(hwaddr, ETHER_ADDR_LEN);	ae = arp_insert(ARP_ENTRY_PENDING, ARP_TTL_PENDING, dst, hwaddr);	if (ae == NULL) {	    /* No more ARP table entries */	    brel(b);	    return;	}	/* Send an ARP request */	arp_send(dst);	/* Queue the packet for transmission */	disable;	benq(b, &(ae->pktq));	enable;	return;    }    /* Send IP packet */    bcopy(ae->hwaddr, eh->dst, ETHER_ADDR_LEN);    netif_send(b);}

⌨️ 快捷键说明

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