2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1995 John Hay. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * static char sccsid[] = "@(#)if.c 5.1 (Berkeley) 6/4/85"; (routed/if.c)
41 static const char sccsid
[] = "@(#)if.c 8.1 (Berkeley) 6/5/93";
45 * Routing Table Management Daemon
49 extern struct interface
*ifnet
;
52 * Find the interface with address addr.
56 struct sockaddr
*addr
;
58 register struct interface
*ifp
;
60 #define same(a1, a2) \
61 (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 10) == 0)
62 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
63 if (ifp
->int_flags
& IFF_REMOTE
)
65 if (ifp
->int_addr
.sa_family
!= addr
->sa_family
)
67 if (same(&ifp
->int_addr
, addr
))
69 if ((ifp
->int_flags
& IFF_BROADCAST
) &&
70 same(&ifp
->int_broadaddr
, addr
))
77 * Find the point-to-point interface with destination address addr.
80 if_ifwithdstaddr(addr
)
81 struct sockaddr
*addr
;
83 register struct interface
*ifp
;
85 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
86 if ((ifp
->int_flags
& IFF_POINTOPOINT
) == 0)
88 if (same(&ifp
->int_dstaddr
, addr
))
95 * Find the interface on the network
96 * of the specified address.
100 register struct sockaddr
*addr
;
102 register struct interface
*ifp
;
103 register int af
= addr
->sa_family
;
104 register int (*netmatch
)();
108 netmatch
= afswitch
[af
].af_netmatch
;
109 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
110 if (ifp
->int_flags
& IFF_REMOTE
)
112 if (af
!= ifp
->int_addr
.sa_family
)
114 if ((*netmatch
)(addr
, &ifp
->int_addr
))
121 * Find an interface from which the specified address
122 * should have come from. Used for figuring out which
123 * interface a packet came in on -- for tracing.
127 struct sockaddr
*addr
;
129 register struct interface
*ifp
, *maybe
;
130 register int af
= addr
->sa_family
;
131 register int (*netmatch
)();
136 netmatch
= afswitch
[af
].af_netmatch
;
137 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
138 if (ifp
->int_addr
.sa_family
!= af
)
140 if (same(&ifp
->int_addr
, addr
))
142 if ((ifp
->int_flags
& IFF_BROADCAST
) &&
143 same(&ifp
->int_broadaddr
, addr
))
145 if (maybe
== 0 && (*netmatch
)(addr
, &ifp
->int_addr
))