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

Fix: added check for if_nametoindex

Amir Khan 8 лет назад
Родитель
Сommit
ed16d415bc
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

+ 5 - 0
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -702,6 +702,11 @@
     [self logMessage:[NSString stringWithFormat:@"bindToDevice: Active interface: %@", activeInterface]];
     
     unsigned int interfaceIndex = if_nametoindex([activeInterface UTF8String]);
+    if (interfaceIndex == 0) {
+        // if_nametoindex returns 0 on error.
+        [self logMessage:[NSString stringWithFormat:@"bindToDevice: if_nametoindex error for interface (%@)", activeInterface]];
+        return FALSE;
+    }
     
     int ret = setsockopt((int)fileDescriptor, IPPROTO_IP, IP_BOUND_IF, &interfaceIndex, sizeof(interfaceIndex));
     if (ret != 0) {