if.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 158 行

C
158
字号
#ifndef lintstatic	char	*sccsid = "@(#)if.c	4.4	(ULTRIX)	10/15/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1984,1988 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * Copyright (c) 1983 Regents of the University of California. * All rights reserved.  The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *//* * 12 June 90 - Peter Grehan, TaN, Sydney, Australia. *		Changed the same(,) macro to only compare the Internet address *		field of a sockaddr structure. *//*#ifndef lintstatic char sccsid[] = "@(#)if.c	4.4 (Berkeley) 10/15/90";#endif not lint*//* * Routing Table Management Daemon */#include "defs.h"extern	struct interface *ifnet;/* * Find the interface with address addr. */struct interface *if_ifwithaddr(addr)	struct sockaddr *addr;{	register struct interface *ifp;#define	same(a1, a2) \ 	(bcmp( &(a1)->sa_data[2], &(a2)->sa_data[2], 4) == 0) 	for (ifp = ifnet; ifp; ifp = ifp->int_next) {		if (ifp->int_flags & IFF_REMOTE)			continue;		if (ifp->int_addr.sa_family != addr->sa_family)			continue;		if (same(&ifp->int_addr, addr))			break;		if ((ifp->int_flags & IFF_BROADCAST) &&		    same(&ifp->int_broadaddr, addr))			break;	}	return (ifp);}/* * Find the point-to-point interface with destination address addr. */struct interface *if_ifwithdstaddr(addr)	struct sockaddr *addr;{	register struct interface *ifp;	for (ifp = ifnet; ifp; ifp = ifp->int_next) {		if ((ifp->int_flags & IFF_POINTOPOINT) == 0)			continue;		if (same(&ifp->int_dstaddr, addr))			break;	}	return (ifp);}/* * Find the interface on the network  * of the specified address. */struct interface *if_ifwithnet(addr)	register struct sockaddr *addr;{	register struct interface *ifp;	register int af = addr->sa_family;	register int (*netmatch)();	if (af >= af_max)		return (0);	netmatch = afswitch[af].af_netmatch;	for (ifp = ifnet; ifp; ifp = ifp->int_next) {		if (ifp->int_flags & IFF_REMOTE)			continue;		if (af != ifp->int_addr.sa_family)			continue;		if ((*netmatch)(addr, &ifp->int_addr))			break;	}	return (ifp);}/* * Find an interface from which the specified address * should have come from.  Used for figuring out which * interface a packet came in on -- for tracing. */struct interface *if_iflookup(addr)	struct sockaddr *addr;{	register struct interface *ifp, *maybe;	register int af = addr->sa_family;	register int (*netmatch)();	if (af >= af_max)		return (0);	maybe = 0;	netmatch = afswitch[af].af_netmatch;	for (ifp = ifnet; ifp; ifp = ifp->int_next) {		if (ifp->int_addr.sa_family != af)			continue;		if (same(&ifp->int_addr, addr))			break;		if ((ifp->int_flags & IFF_BROADCAST) &&		    same(&ifp->int_broadaddr, addr))			break;		if ((ifp->int_flags & IFF_POINTOPOINT) &&		    same(&ifp->int_dstaddr, addr))			break;		if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr))			maybe = ifp;	}	if (ifp == 0)		ifp = maybe;	return (ifp);}

⌨️ 快捷键说明

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