This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit d802fef5179dfb7bb5102e40a9c474917682d789 Author: Daniel P. Carvalho <[email protected]> AuthorDate: Sun Oct 18 18:11:27 2026 -0300 system/brctl: use the netlib bridge helpers. Replace the private ioctl wrappers with netlib_add_bridge(), netlib_del_bridge(), netlib_bridge_addif() and netlib_bridge_delif(). The command no longer opens a socket itself. Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Daniel P. Carvalho <[email protected]> --- system/brctl/Kconfig | 1 + system/brctl/brctl.c | 45 ++++++--------------------------------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/system/brctl/Kconfig b/system/brctl/Kconfig index f4323c0d9..6b4de7c44 100644 --- a/system/brctl/Kconfig +++ b/system/brctl/Kconfig @@ -7,6 +7,7 @@ config SYSTEM_BRCTL tristate "Ethernet bridge 'brctl' command" default n depends on NET_BRIDGE + select NETUTILS_NETLIB ---help--- Enable the 'brctl' command to create Ethernet bridges and to add or remove their ports. diff --git a/system/brctl/brctl.c b/system/brctl/brctl.c index 1fec14213..189e2ff93 100644 --- a/system/brctl/brctl.c +++ b/system/brctl/brctl.c @@ -26,18 +26,11 @@ #include <nuttx/config.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <net/if.h> -#include <nuttx/net/ioctl.h> -#include <nuttx/net/netconfig.h> +#include "netutils/netlib.h" /**************************************************************************** * Private Functions @@ -52,22 +45,6 @@ static void brctl_usage(FAR const char *progname) fprintf(stderr, " %s delif <bridge> <device>\n", progname); } -static int brctl_ifcmd(int sockfd, int cmd, FAR const char *bridge, - FAR const char *ifname) -{ - struct ifreq req; - - memset(&req, 0, sizeof(req)); - strlcpy(req.ifr_name, bridge, IFNAMSIZ); - req.ifr_ifindex = if_nametoindex(ifname); - if (req.ifr_ifindex == 0) - { - return -1; - } - - return ioctl(sockfd, cmd, (unsigned long)(uintptr_t)&req); -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -75,7 +52,6 @@ static int brctl_ifcmd(int sockfd, int cmd, FAR const char *bridge, int main(int argc, FAR char *argv[]) { FAR const char *cmd; - int sockfd; int ret; if (argc < 3) @@ -86,32 +62,24 @@ int main(int argc, FAR char *argv[]) cmd = argv[1]; - sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); - if (sockfd < 0) - { - fprintf(stderr, "ERROR: socket failed: %d\n", errno); - return EXIT_FAILURE; - } - if (strcmp(cmd, "addbr") == 0 && argc == 3) { - ret = ioctl(sockfd, SIOCBRADDBR, (unsigned long)(uintptr_t)argv[2]); + ret = netlib_add_bridge(argv[2]); } else if (strcmp(cmd, "delbr") == 0 && argc == 3) { - ret = ioctl(sockfd, SIOCBRDELBR, (unsigned long)(uintptr_t)argv[2]); + ret = netlib_del_bridge(argv[2]); } else if (strcmp(cmd, "addif") == 0 && argc == 4) { - ret = brctl_ifcmd(sockfd, SIOCBRADDIF, argv[2], argv[3]); + ret = netlib_bridge_addif(argv[2], argv[3]); } else if (strcmp(cmd, "delif") == 0 && argc == 4) { - ret = brctl_ifcmd(sockfd, SIOCBRDELIF, argv[2], argv[3]); + ret = netlib_bridge_delif(argv[2], argv[3]); } else { - close(sockfd); brctl_usage(argv[0]); return EXIT_FAILURE; } @@ -119,9 +87,8 @@ int main(int argc, FAR char *argv[]) if (ret < 0) { fprintf(stderr, "ERROR: brctl %s failed: %s\n", cmd, - strerror(errno)); + strerror(-ret)); } - close(sockfd); return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
