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

📄 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 <errno.h>#include <fs.h>#include <net/ether.h>#include <net/tcp.h>#if _DEBUG#include <stdio.h>#endif#include <stdlib.h>#include <string.h>#include <sys/intr.h>#include <sys/socket.h>ssize_tsend(int s, const void *msg, size_t len, int flags){    socket_t socket;    buf_t b;    etherhdr_t eh;    iphdr_t ih;    tcphdr_t th;    int datalen, hdrlen, nleft, pos = 0;    if (s < 0 || s >= FILES)	return EINVAL;    if (filetab[s].type != FT_SOCKET)	return ENOTSOCK;    socket = (socket_t) filetab[s].data;    if (socket->state != SS_CONNECTED)	return ENOTCONN;    hdrlen = ETHER_HDR_LEN + sizeof(struct iphdr) + sizeof(struct tcphdr);    datalen = ETHER_PKT_LEN - hdrlen;    for (nleft = len; nleft > 0;) {	b = _bget(ETHER_PKT_LEN);	if (b == NULL)	    return 0;	blen(b) = hdrlen;	eh = (etherhdr_t) bstart(b);	ih = (iphdr_t) eh->data;	th = (tcphdr_t) (((char *) ih) + sizeof(struct iphdr));	bpos(b) = ((char *) th) - bstart(b) + sizeof(struct tcphdr);	if (nleft >= datalen) {	    bcopy(((char *) msg) + pos, bstart(b) + bpos(b), datalen);	    blen(b) += datalen;	    bpos(b) += datalen;	    pos += datalen;	    nleft -= datalen;	    socket->snd_cc += datalen;	} else {	    bcopy(((char *) msg) + pos, bstart(b) + bpos(b), nleft);	    blen(b) += nleft;	    socket->snd_cc += nleft;	    nleft = 0;	}	disable;	benq(b, &(socket->sndq));	enable;    }    tcp_send((tcb_t) socket->pcb);    return len - nleft;}

⌨️ 快捷键说明

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