udp_in.c

来自「关于UDP方面的东西。。看不懂就算了。不适合基础者。」· C语言 代码 · 共 56 行

C
56
字号
/* udp_in.c - udp_in */#include <conf.h>#include <kernel.h>#include <proc.h>#include <network.h>#include <ports.h>/*------------------------------------------------------------------------ *  udp_in -  handle an inbound UDP datagram *------------------------------------------------------------------------ */intudp_in(struct netif *pni, struct ep *pep){	struct	ip	*pip = (struct ip *)pep->ep_data;	struct	udp	*pudp = (struct udp *)pip->ip_data;	struct	upq	*pup;	unsigned short	dst;	int		i;	if (pudp->u_cksum && udpcksum(pep, net2hs(pudp->u_len))) {		freebuf(pep);		return SYSERR;			/* checksum error */	}	udpnet2h(pudp);		/* convert UDP header to host order */	dst = pudp->u_dst;	wait(udpmutex);	for (i=0 ; i<UPPS ; i++) {		pup = &upqs[i];		if (pup->up_port == dst) {			/* drop instead of blocking on psend */ 			if (pcount(pup->up_xport) >= UPPLEN) {				signal(udpmutex);				freebuf(pep);				UdpInErrors++;				return SYSERR;			}			psend(pup->up_xport, (WORD)pep);			UdpInDatagrams++;			if (!isbadpid(pup->up_pid)) {				send(pup->up_pid, OK);				pup->up_pid = BADPID;			}			signal(udpmutex);			return OK;		}	}	signal(udpmutex);	UdpNoPorts++;	icmp(ICT_DESTUR, ICC_PORTUR, pip->ip_src, pep, 0);	return OK;}int	udpmutex;

⌨️ 快捷键说明

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