Просмотр исходного кода

Fix doc and segfault with invalid interface

At the courtesy of Scott Newell, this patch fixes the location of the
executable and more important handles if an invalid interface is
provided at startup, closing OpENer with an error message, instead of a
segfault

Signed-off-by: Martin Melik Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik Merkumians 7 лет назад
Родитель
Сommit
210c688bae
3 измененных файлов с 10 добавлено и 3 удалено
  1. 2 2
      README.md
  2. 4 1
      source/src/ports/POSIX/main.c
  3. 4 0
      source/src/ports/POSIX/networkconfig.c

+ 2 - 2
README.md

@@ -60,9 +60,9 @@ Compile for POSIX:
 	3. Invoke make
 	4. For invoking opener type:
 
-		./OpENer interface
+		./src/ports/POSIX/OpENer interface
 
-		e.g. ./OpENer eth1
+		e.g. ./src/ports/POSIX/OpENer eth1
  
 2. Within Eclipse
 	1. For a standard configuration invoke setup_posix.sh, otherwise start

+ 4 - 1
source/src/ports/POSIX/main.c

@@ -43,7 +43,10 @@ int main(int argc,
                                CipConnectionObjectListArrayAllocator,
                                CipConnectionObjectListArrayFree);
     /* fetch Internet address info from the platform */
-    ConfigureNetworkInterface(arg[1]);
+    if (kEipStatusError == ConfigureNetworkInterface(arg[1])) {
+      printf("Network interface %s not found.\n", arg[1]);
+      exit(0);
+    }
     ConfigureDomainName();
     ConfigureHostName();
 

+ 4 - 0
source/src/ports/POSIX/networkconfig.c

@@ -61,10 +61,14 @@ EipStatus ConfigureNetworkInterface(const char *const network_interface) {
   int netaddr = 0;
   if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
     ipaddr = ( (struct sockaddr_in *) &ifr.ifr_addr )->sin_addr.s_addr;
+  } else {
+    return kEipStatusError;
   }
 
   if (ioctl(fd, SIOCGIFNETMASK, &ifr) == 0) {
     netaddr = ( (struct sockaddr_in *) &ifr.ifr_netmask )->sin_addr.s_addr;
+  } else {
+    return kEipStatusError;
   }
 
   interface_configuration_.ip_address = ipaddr;