diff options
author | Ryan Moeller <freqlabs@FreeBSD.org> | 2020-10-21 05:27:25 +0000 |
---|---|---|
committer | Ryan Moeller <freqlabs@FreeBSD.org> | 2020-10-21 05:27:25 +0000 |
commit | 0710ec8ceff0b30f773ac606f29312275513b910 (patch) | |
tree | 9bbbfc85e95e8dd86327fe32ed239270350df2b4 /lib/libifconfig | |
parent | c0b5fcf6922574a5facf8c31f7066e6d6341cd82 (diff) | |
download | src-test-0710ec8ceff0b30f773ac606f29312275513b910.tar.gz src-test-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 'lib/libifconfig')
-rw-r--r-- | lib/libifconfig/libifconfig.c | 32 | ||||
-rw-r--r-- | lib/libifconfig/libifconfig.h | 10 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/libifconfig/libifconfig.c b/lib/libifconfig/libifconfig.c index 4d6e702db9dec..e67c4e4de04e7 100644 --- a/lib/libifconfig/libifconfig.c +++ b/lib/libifconfig/libifconfig.c @@ -628,3 +628,35 @@ ifconfig_set_vlantag(ifconfig_handle_t *h, const char *name, } return (0); } + +int +ifconfig_list_cloners(ifconfig_handle_t *h, char **bufp, size_t *lenp) +{ + struct if_clonereq ifcr; + char *buf; + + memset(&ifcr, 0, sizeof(ifcr)); + *bufp = NULL; + *lenp = 0; + + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFGCLONERS, &ifcr) < 0) + return (-1); + + buf = malloc(ifcr.ifcr_total * IFNAMSIZ); + if (buf == NULL) { + h->error.errtype = OTHER; + h->error.errcode = ENOMEM; + return (-1); + } + + ifcr.ifcr_count = ifcr.ifcr_total; + ifcr.ifcr_buffer = buf; + if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCIFGCLONERS, &ifcr) < 0) { + free(buf); + return (-1); + } + + *bufp = buf; + *lenp = ifcr.ifcr_total; + return (0); +} diff --git a/lib/libifconfig/libifconfig.h b/lib/libifconfig/libifconfig.h index ca8e8e817dc1f..46a13ae27d69b 100644 --- a/lib/libifconfig/libifconfig.h +++ b/lib/libifconfig/libifconfig.h @@ -279,3 +279,13 @@ int ifconfig_create_interface_vlan(ifconfig_handle_t *h, const char *name, int ifconfig_set_vlantag(ifconfig_handle_t *h, const char *name, const char *vlandev, const unsigned short vlantag); + +/** Gets the names of all interface cloners available on the system + * @param bufp Set to the address of the names buffer on success or NULL + * if an error occurs. This buffer must be freed when done. + * @param lenp Set to the number of names in the returned buffer or 0 + * if an error occurs. Each name is contained within an + * IFNAMSIZ length slice of the buffer, for a total buffer + * length of *lenp * IFNAMSIZ bytes. + */ +int ifconfig_list_cloners(ifconfig_handle_t *h, char **bufp, size_t *lenp); |