-/* $OpenBSD: show.c,v 1.121 2022/11/09 18:00:02 kn Exp $ */
+/* $OpenBSD: show.c,v 1.122 2023/03/15 08:42:14 claudio Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
void
printsource(int af, u_int tableid)
{
- struct sockaddr *sa;
+ struct sockaddr *sa, *sa4 = NULL, *sa6 = NULL;
char *buf = NULL, *next, *lim = NULL;
size_t needed;
- int mib[7], mcnt, size;
+ int mib[7], mcnt;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
if (pledge("stdio", NULL) == -1)
err(1, "pledge");
- printf("Preferred source address set for rdomain %d\n", tableid);
-
if (buf) {
- for (next = buf; next < lim; next += size) {
+ for (next = buf; next < lim; next += sa->sa_len) {
sa = (struct sockaddr *)next;
switch (sa->sa_family) {
case AF_INET:
- size = sizeof(struct sockaddr_in);
- printf("IPv4: ");
+ sa4 = sa;
break;
case AF_INET6:
- size = sizeof(struct sockaddr_in6);
- printf("IPv6: ");
+ sa6 = sa;
break;
}
- p_sockaddr(sa, NULL, RTF_HOST, WID_DST(sa->sa_family));
- printf("\n");
}
}
+
+ printf("Preferred source address set for rdomain %d\n", tableid);
+ printf("IPv4: ");
+ if (sa4 != NULL)
+ p_sockaddr(sa4, NULL, RTF_HOST, WID_DST(sa4->sa_family));
+ else
+ printf("default");
+ printf("\n");
+ printf("IPv6: ");
+ if (sa6 != NULL)
+ p_sockaddr(sa6, NULL, RTF_HOST, WID_DST(sa6->sa_family));
+ else
+ printf("default");
+ printf("\n");
free(buf);
exit(0);