diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-03-15 08:42:15 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-03-15 08:42:15 +0000 |
commit | 8da3374f0bdfdc05e103ce92887e6ff6dd3396f4 (patch) | |
tree | 37307ee00a37edcbcfeb7abb2d6d779e06b27823 /sbin/route | |
parent | 05cc9e720c4701481208c0e4e72eea99d477b8cd (diff) |
Make route sourceaddr always print the used addresses for inet and inet6.
Print 'default' if no sourceaddr is set and the default algorithm is used.
With and OK kn@ deraadt@
Diffstat (limited to 'sbin/route')
-rw-r--r-- | sbin/route/show.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/sbin/route/show.c b/sbin/route/show.c index 1b1a695a7c2..9878349a6ec 100644 --- a/sbin/route/show.c +++ b/sbin/route/show.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -136,10 +136,10 @@ get_sysctl(const int *mib, u_int mcnt, char **buf) 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; @@ -155,25 +155,33 @@ printsource(int af, u_int tableid) 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); |