2004-10-22 Paul Jakma <paul@dishone.st>
* ripd.c: Collapse redundant passing of various address structs,
struct interface and struct connected as arguments to functions
down to two key arguments, namely struct connected and, possibly,
address of source/destination. Testing for RIPv1 would be useful.
(rip_read) lookup struct connected for the received packet, pass
it on.
* rip_interface.c: With previous changes, we no longer have to tread
carefully with struct connected, as it will always be there and
valid.
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index 19f6f11..c1c0a45 100644
--- a/ripd/rip_interface.c
+++ b/ripd/rip_interface.c
@@ -145,19 +145,15 @@
struct sockaddr_in from;
struct in_addr addr;
struct prefix_ipv4 *p;
-
- if (connected != NULL)
- {
- if (if_is_pointopoint(connected->ifp) && CONNECTED_DEST_HOST(connected))
- p = (struct prefix_ipv4 *) connected->destination;
- else
- p = (struct prefix_ipv4 *) connected->address;
- addr = p->prefix;
- }
- else
- {
- addr.s_addr = INADDR_ANY;
- }
+
+ assert (connected != NULL);
+
+ if (if_is_pointopoint(connected->ifp) && CONNECTED_DEST_HOST(connected))
+ p = (struct prefix_ipv4 *) connected->destination;
+ else
+ p = (struct prefix_ipv4 *) connected->address;
+
+ addr = p->prefix;
if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF, addr, 0,
connected->ifp->ifindex) < 0)
@@ -165,7 +161,7 @@
zlog_warn ("Can't setsockopt IP_MULTICAST_IF on fd %d to "
"source address %s for interface %s",
sock, inet_ntoa(addr),
- (connected ? connected->ifp->name : "(unknown)"));
+ connected->ifp->name);
return;
}
@@ -181,9 +177,7 @@
/* Address should be any address. */
from.sin_family = AF_INET;
- if (connected)
- addr = ((struct prefix_ipv4 *) connected->address)->prefix;
- from.sin_addr = addr;
+ from.sin_addr = connected->address->u.prefix4;
#ifdef HAVE_SIN_LEN
from.sin_len = sizeof (struct sockaddr_in);
#endif /* HAVE_SIN_LEN */
@@ -198,7 +192,7 @@
"interface %s: %s",
sock,inet_ntoa(from.sin_addr),
(int)ntohs(from.sin_port),
- (connected ? connected->ifp->name : "(unknown)"),
+ connected->ifp->name,
strerror (errno));
}