From de046edb4d5106e20fe737e5333af5ef1733fe7e Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Tue, 19 May 2020 21:03:51 +0900 Subject: [PATCH] Print errno when socket and ioctl fail Change-Id: I29f6264dd8db405405494f360c9543a33d342bb9 Signed-off-by: Cheoleun Moon --- src/utils/util.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/util.c b/src/utils/util.c index f113032..26beb05 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -370,19 +370,23 @@ gboolean netconfig_interface_up(const char *ifname) struct ifreq ifr; fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) + if (fd < 0) { + ERR("socket failed %d", errno); return FALSE; + } memset(&ifr, 0, sizeof(ifr)); g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + ERR("Fail to get IFFLAGS %d", errno); close(fd); return FALSE; } ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC); if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + ERR("Fail to set IFFLAGS %d", errno); close(fd); return FALSE; } @@ -399,19 +403,23 @@ gboolean netconfig_interface_down(const char *ifname) struct ifreq ifr; fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) + if (fd < 0) { + ERR("socket failed %d", errno); return FALSE; + } memset(&ifr, 0, sizeof(ifr)); g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + ERR("Fail to get IFFLAGS %d", errno); close(fd); return FALSE; } ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC; if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + ERR("Fail to set IFFLAGS %d", errno); close(fd); return FALSE; } -- 2.7.4