PUD: remove usage of getifaddrs
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 19 Jun 2012 09:39:38 +0000 (11:39 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 19 Jun 2012 11:36:01 +0000 (13:36 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/configuration.c
lib/pud/src/networkInterfaces.c

index 0dc6f48..7640fb8 100644 (file)
@@ -1412,52 +1412,5 @@ unsigned int checkConfig(void) {
  - false otherwise
  */
 unsigned int checkRunSetup(void) {
-       int retval = true;
-       unsigned int i;
-
-       /* any receive interface name that is configured but is not the name of an
-        * actual receive interface is not a valid interface name */
-       for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
-               unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
-
-               TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
-               bool found = false;
-               while (interfaceObject != NULL) {
-                       if (strncmp((char *) nonOlsrInterfaceName,
-                                       (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
-                               found = true;
-                               break;
-                       }
-                       interfaceObject = interfaceObject->next;
-               }
-               if (!found) {
-                       pudError(false, "Configured receive non-OLSR interface %s is not"
-                               " a known interface name", nonOlsrInterfaceName);
-                       retval = false;
-               }
-       }
-
-       /* any transmit interface name that is configured but is not the name of an
-        * actual transmit interface is not a valid interface name */
-       for (i = 0; i < txNonOlsrInterfaceCount; i++) {
-               unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
-
-               TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
-               bool found = false;
-               while (interfaceObject != NULL) {
-                       if (strncmp((char *) nonOlsrInterfaceName,
-                                       (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
-                               found = true;
-                               break;
-                       }
-                       interfaceObject = interfaceObject->next;
-               }
-               if (!found) {
-                       pudError(false, "Configured transmit non-OLSR interface %s is not"
-                               " a known interface name", nonOlsrInterfaceName);
-                       retval = false;
-               }
-       }
-
-       return retval;
+       return true;
 }
index 9fd9685..be55eb7 100644 (file)
@@ -12,7 +12,6 @@
 /* System includes */
 #include <unistd.h>
 #include <fcntl.h>
-#include <ifaddrs.h>
 
 /*
  * Main IP MAC address
@@ -590,61 +589,45 @@ static int createDownlinkSocket(int ipVersion, socket_handler_func rxSocketHandl
  */
 bool createNetworkInterfaces(socket_handler_func rxSocketHandlerFunction,
                socket_handler_func rxSocketHandlerFunctionDownlink) {
-       int retval = false;
-       struct ifaddrs *ifAddrs = NULL;
-       struct ifaddrs *ifAddr = NULL;
+       TRxTxNetworkInterface * interfaces;
        union olsr_sockaddr * rxMcAddr = getRxMcAddr();
        union olsr_sockaddr * txMcAddr = getTxMcAddr();
 
-       errno = 0;
-       if (getifaddrs(&ifAddrs) != 0) {
-               pudError(true, "Could not get list of interfaces and their addresses");
-               return retval;
-       }
-
-       /* loop over all interfaces */
-       for (ifAddr = ifAddrs; ifAddr != NULL; ifAddr = ifAddr->ifa_next) {
-               union olsr_sockaddr * addr = (union olsr_sockaddr *)ifAddr->ifa_addr;
-               if ((addr != NULL) && ((addr->in.sa_family == AF_INET) || (addr->in.sa_family == AF_INET6))) {
-                       char * ifName = ifAddr->ifa_name;
-
-                       /* determine whether the iterated interface is configured as a
-                        * non-OLSR interface in the plugin parameter list */
-                       bool isRxNonOlsrIf = isRxNonOlsrInterface(ifName) && (addr->in.sa_family == rxMcAddr->in.sa_family);
-                       bool isTxNonOlsrIf = isTxNonOlsrInterface(ifName) && (addr->in.sa_family == txMcAddr->in.sa_family);
-
-                       bool isNonOlsrIf = isRxNonOlsrIf || isTxNonOlsrIf;
-
-                       if (!isNonOlsrIf) {
-                               /* interface is not configured as non-OLSR interface: skip */
-                               continue;
-                       }
-
-                       if (isRxNonOlsrIf && !createRxInterface(ifName, rxSocketHandlerFunction, rxMcAddr)) {
+       /* loop over all configured rx interfaces */
+       interfaces = getRxNetworkInterfaces();
+       if (interfaces) {
+               TRxTxNetworkInterface * interface;
+               for (interface = interfaces; interface != NULL; interface = interfaces->next) {
+                       if (!createRxInterface(interface->name, rxSocketHandlerFunction, rxMcAddr)) {
                                /* creating a receive interface failed */
-                               goto end;
+                               return false;
                        }
+               }
+       }
 
-                       if (isTxNonOlsrIf && !createTxInterface(ifName, txMcAddr)) {
+       /* loop over all configured tx interfaces */
+       interfaces = getTxNetworkInterfaces();
+       if (interfaces) {
+               TRxTxNetworkInterface * interface;
+               for (interface = interfaces; interface != NULL; interface = interfaces->next) {
+                       if (!createTxInterface(interface->name, txMcAddr)) {
                                /* creating a transmit interface failed */
-                               goto end;
+                               return false;
                        }
                }
        }
 
+       /* create uplink socket when needed */
        if (isUplinkAddrSet()) {
                downlinkSocketFd = createDownlinkSocket(getUplinkAddr()->in.sa_family, rxSocketHandlerFunctionDownlink);
                if (downlinkSocketFd == -1) {
-                       goto end;
+                       return false;
                }
        } else {
                downlinkSocketFd = -1;
        }
 
-       retval = true;
-
-       end: freeifaddrs(ifAddrs);
-       return retval;
+       return true;
 }
 
 /**