aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorRyan Moeller <freqlabs@FreeBSD.org>2020-10-21 05:27:25 +0000
committerRyan Moeller <freqlabs@FreeBSD.org>2020-10-21 05:27:25 +0000
commit0710ec8ceff0b30f773ac606f29312275513b910 (patch)
tree9bbbfc85e95e8dd86327fe32ed239270350df2b4 /sbin/ifconfig
parentc0b5fcf6922574a5facf8c31f7066e6d6341cd82 (diff)
downloadsrc-0710ec8ceff0b30f773ac606f29312275513b910.tar.gz
src-0710ec8ceff0b30f773ac606f29312275513b910.zip
Move list_cloners to libifconfig
Move list_cloners() from ifconfig(8) to libifconfig(3) where it can be reused by other consumers. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D26858
Notes
Notes: svn path=/head/; revision=366906
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifclone.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c
index c264a444dcf0..134bb0af3efa 100644
--- a/sbin/ifconfig/ifclone.c
+++ b/sbin/ifconfig/ifclone.c
@@ -41,6 +41,7 @@ static const char rcsid[] =
#include <net/if.h>
#include <err.h>
+#include <libifconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -51,45 +52,27 @@ static const char rcsid[] =
static void
list_cloners(void)
{
- struct if_clonereq ifcr;
- char *cp, *buf;
- int idx;
- int s;
-
- s = socket(AF_LOCAL, SOCK_DGRAM, 0);
- if (s == -1)
- err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
-
- memset(&ifcr, 0, sizeof(ifcr));
-
- if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
- err(1, "SIOCIFGCLONERS for count");
-
- buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
- if (buf == NULL)
- err(1, "unable to allocate cloner name buffer");
-
- ifcr.ifcr_count = ifcr.ifcr_total;
- ifcr.ifcr_buffer = buf;
-
- if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
- err(1, "SIOCIFGCLONERS for names");
-
- /*
- * In case some disappeared in the mean time, clamp it down.
- */
- if (ifcr.ifcr_count > ifcr.ifcr_total)
- ifcr.ifcr_count = ifcr.ifcr_total;
-
- for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) {
- if (idx > 0)
+ ifconfig_handle_t *lifh;
+ char *cloners;
+ size_t cloners_count;
+
+ lifh = ifconfig_open();
+ if (lifh == NULL)
+ return;
+
+ if (ifconfig_list_cloners(lifh, &cloners, &cloners_count) < 0)
+ errc(1, ifconfig_err_errno(lifh), "unable to list cloners");
+ ifconfig_close(lifh);
+
+ for (const char *name = cloners;
+ name < cloners + cloners_count * IFNAMSIZ;
+ name += IFNAMSIZ) {
+ if (name > cloners)
putchar(' ');
- printf("%s", cp);
+ printf("%s", name);
}
-
putchar('\n');
- free(buf);
- close(s);
+ free(cloners);
}
struct clone_defcb {