tcpbind.c,v

来自「TCP-IP红宝书源代码」· C,V 代码 · 共 98 行

C,V
98
字号
head	1.2;
access;
symbols;
locks
	dls:1.2; strict;
comment	@ * @;


1.2
date	97.09.21.19.30.11;	author dls;	state Dist;
branches;
next	1.1;

1.1
date	94.01.14.04.11.50;	author dls;	state v2e1;
branches;
next	;


desc
@@


1.2
log
@pre-3e code
@
text
@/* tcpbind.c - tcpbind */

#include <conf.h>
#include <kernel.h>
#include <network.h>

/*------------------------------------------------------------------------
 *  tcpbind - bind a TCP pseudo device to its addresses and port
 *------------------------------------------------------------------------
 */
int tcpbind(ptcb, fport, lport)
struct	tcb	*ptcb;
char		*fport;
int		lport;
{
	struct	route	*prt, *rtget();
	struct	tcb	*ptcb2;
	int		slot;

	if (dnparse(fport, &ptcb->tcb_rip, &ptcb->tcb_rport) == SYSERR)
		return SYSERR;
	prt = rtget(ptcb->tcb_rip, RTF_LOCAL);
	if (prt == 0)
		return SYSERR;
	if (prt->rt_ifnum == NI_LOCAL)
		ptcb->tcb_lip = ptcb->tcb_rip;
	else
		ptcb->tcb_lip = nif[prt->rt_ifnum].ni_ip;
	ptcb->tcb_pni = &nif[prt->rt_ifnum];
	rtfree(prt);
	if (lport == ANYLPORT) {
		ptcb->tcb_lport = tcpnxtp();	/* pick one */
		return OK;
	}
	ptcb->tcb_lport = lport;
	for (slot=0, ptcb2=&tcbtab[0]; slot<Ntcp; ++slot, ++ptcb2) {
		if (ptcb == ptcb2 ||
		    ptcb2->tcb_state == TCPS_FREE ||
		    ptcb->tcb_rport != ptcb2->tcb_rport ||
		    ptcb->tcb_lport != ptcb2->tcb_lport ||
		    ptcb->tcb_rip != ptcb2->tcb_rip ||
		    ptcb->tcb_lip != ptcb2->tcb_lip)
			continue;
		return SYSERR;
	}
	return OK;
}
@


1.1
log
@Initial revision
@
text
@d20 1
a20 1
	if (dnparse(fport, ptcb->tcb_rip, &ptcb->tcb_rport) == SYSERR)
d26 1
a26 1
		blkcopy(ptcb->tcb_lip, ptcb->tcb_rip, IP_ALEN);
d28 1
a28 1
		blkcopy(ptcb->tcb_lip, nif[prt->rt_ifnum].ni_ip, IP_ALEN);
d41 2
a42 2
		    !blkequ(ptcb->tcb_rip, ptcb2->tcb_rip, IP_ALEN) ||
		    !blkequ(ptcb->tcb_lip, ptcb2->tcb_lip, IP_ALEN))
@

⌨️ 快捷键说明

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