hgjoin.c,v

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

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


1.1
date	97.09.21.19.26.58;	author dls;	state Dist;
branches;
next	;


desc
@@


1.1
log
@pre-3e code
@
text
@/* hgjoin.c - hgjoin */

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

/*------------------------------------------------------------------------
 *  hgjoin  -  handle application request to join a host group
 *------------------------------------------------------------------------
 */
int hgjoin(ifnum, ipa, islocal)
int	ifnum;		/* interface of the group address	*/
IPaddr	ipa;		/* IP address of the multicast group	*/
Bool	islocal;	/* use local multicast (ttl 1) if true	*/
{
	struct	hg	*phg, *hglookup();
	int		i;

	if (!IP_CLASSD(ipa))
		return SYSERR;
	/* restrict multicast in multi-homed host to primary interface */
	if (ifnum != NI_PRIMARY)
		return SYSERR;
	wait(HostGroup.hi_mutex);
	if (phg = hglookup(ifnum, ipa)) {
		phg->hg_refs++;
		signal(HostGroup.hi_mutex);
		return OK;	/* already in it */
	}
	signal(HostGroup.hi_mutex);
	/* add to host group and routing tables */
	if (hgadd(ifnum, ipa, islocal) == SYSERR)
		return SYSERR;
	rtadd(ipa, ip_maskall, ipa, 0, NI_LOCAL, RT_INF);
	/*
	 * advertise membership to multicast router(s); don't advertise
	 * 224.0.0.1 (all multicast hosts) membership.
	 */
	if (ipa != ig_allhosts)
		for (i=0; i < IG_NSEND; ++i) {
			igmp(IGT_HREPORT, ifnum, ipa);
			sleep10(IG_DELAY);
		}
	return OK;
}
@

⌨️ 快捷键说明

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