From 61ee862c33507f68e82af5fa0d594583d404525e Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 17 Apr 2014 15:35:35 +0000 Subject: [PATCH] Sync show.c to what we have in netstat.c (at least steal some good idioms from there). OK sthen@ mpi@ jca@ --- sbin/route/show.c | 34 ++++++++++++++++------------------ sbin/route/show.h | 9 ++++++++- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/sbin/route/show.c b/sbin/route/show.c index 6540970dfc3..59fe7eae26a 100644 --- a/sbin/route/show.c +++ b/sbin/route/show.c @@ -1,4 +1,4 @@ -/* $OpenBSD: show.c,v 1.94 2013/07/19 20:10:23 guenther Exp $ */ +/* $OpenBSD: show.c,v 1.95 2014/04/17 15:35:35 claudio Exp $ */ /* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */ /* @@ -60,13 +60,6 @@ char *any_ntoa(const struct sockaddr *); char *link_print(struct sockaddr *); char *label_print(struct sockaddr *); -extern int nflag; -extern int Fflag; -extern int verbose; -extern union sockunion so_label; - -#define PLEN (LONG_BIT / 4 + 2) /* XXX this is also defined in netstat.h */ - #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) @@ -151,7 +144,7 @@ p_rttables(int af, u_int tableid, int hastable) if (needed == 0) break; if ((buf = realloc(buf, needed)) == NULL) - err(1, "realloc"); + err(1, NULL); if (sysctl(mib, mcnt, buf, &needed, NULL, 0) == -1) { if (errno == ENOMEM) continue; @@ -185,18 +178,23 @@ p_rttables(int af, u_int tableid, int hastable) mib[2] = PF_KEY_V2; mib[3] = NET_KEY_SPD_DUMP; mib[4] = mib[5] = 0; - - if (sysctl(mib, 4, NULL, &needed, NULL, 0) == -1) { - if (errno == ENOPROTOOPT) - return; - err(1, "spd-sysctl-estimate"); - } - if (needed > 0) { - if ((buf = malloc(needed)) == 0) + while (1) { + if (sysctl(mib, 4, NULL, &needed, NULL, 0) == -1) { + if (errno == ENOPROTOOPT) + return; + err(1, "spd-sysctl-estimate"); + } + if (needed == 0) + break; + if ((buf = realloc(buf, needed)) == NULL) err(1, NULL); - if (sysctl(mib, 4, buf, &needed, NULL, 0) == -1) + if (sysctl(mib, 4, buf, &needed, NULL, 0) == -1) { + if (errno == ENOMEM) + continue; err(1,"sysctl of spd"); + } lim = buf + needed; + break; } if (buf) { diff --git a/sbin/route/show.h b/sbin/route/show.h index 9edfb545311..ab5977a9bad 100644 --- a/sbin/route/show.h +++ b/sbin/route/show.h @@ -1,4 +1,4 @@ -/* $OpenBSD: show.h,v 1.9 2010/10/11 11:45:00 claudio Exp $ */ +/* $OpenBSD: show.h,v 1.10 2014/04/17 15:35:35 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker @@ -33,4 +33,11 @@ char *routename(struct sockaddr *); char *netname(struct sockaddr *, struct sockaddr *); char *mpls_op(u_int32_t); +extern int nflag; +extern int Fflag; +extern int verbose; +extern union sockunion so_label; + +#define PLEN (LONG_BIT / 4 + 2) + #endif /* __SHOW_H__ */ -- 2.20.1