net: faster struct cleaning
authorRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 18:12:48 +0000 (19:12 +0100)
committerRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 18:12:48 +0000 (19:12 +0100)
log.h
net.cc

diff --git a/log.h b/log.h
index 04076d305b44d084ca35ce2dfe3031a4c2516b98..14b7e75c9e5efe36589e807093126c5f8a63abaa 100644 (file)
--- a/log.h
+++ b/log.h
@@ -28,7 +28,8 @@
 #include "nsjail.h"
 
 #define LOG_HELP(...) log::logMsg(HELP, __PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__);
-#define LOG_HELP_BOLD(...) log::logMsg(HELP_BOLD, __PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__);
+#define LOG_HELP_BOLD(...) \
+       log::logMsg(HELP_BOLD, __PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__);
 
 #define LOG_D(...) log::logMsg(DEBUG, __PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__);
 #define LOG_I(...) log::logMsg(INFO, __PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__);
diff --git a/net.cc b/net.cc
index d9e5d106f5a31c8b9b4c14657ce887e8b851032e..e96b40f80d90a466f5345e3f7982c72283e7d332 100644 (file)
--- a/net.cc
+++ b/net.cc
@@ -302,8 +302,7 @@ static bool ifaceUp(const char* ifacename) {
                return false;
        }
 
-       struct ifreq ifr;
-       memset(&ifr, '\0', sizeof(ifr));
+       struct ifreq ifr = {};
        snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", ifacename);
 
        if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) {
@@ -325,8 +324,7 @@ static bool ifaceUp(const char* ifacename) {
 }
 
 static bool netConfigureVs(struct nsjconf_t* nsjconf) {
-       struct ifreq ifr;
-       memset(&ifr, '\0', sizeof(ifr));
+       struct ifreq ifr = {};
        snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", IFACE_NAME);
        struct in_addr addr;
 
@@ -385,8 +383,7 @@ static bool netConfigureVs(struct nsjconf_t* nsjconf) {
                return true;
        }
 
-       struct rtentry rt;
-       memset(&rt, '\0', sizeof(rt));
+       struct rtentry rt = {};
 
        struct sockaddr_in* sdest = (struct sockaddr_in*)(&rt.rt_dst);
        struct sockaddr_in* smask = (struct sockaddr_in*)(&rt.rt_genmask);