[vlc-commits] [Git][videolan/vlc][3.0.x] bonjour SD: resolve hostname to IP for SMB

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat Apr 16 06:55:40 UTC 2022



Felix Paul Kühne pushed to branch 3.0.x at VideoLAN / VLC


Commits:
d4c8f5c0 by Felix Paul Kühne at 2022-04-16T06:41:14+00:00
bonjour SD: resolve hostname to IP for SMB

The SMB modules cannot do the Bonjour lookup, so resolve the hostname
and forward the first IP, which typically is the preferred value.

This fixes vlc-ios#1319

(cherry picked from commit 2d52141e145f2cde00612aabf4d6835b998c2f60)

- - - - -


1 changed file:

- modules/services_discovery/bonjour.m


Changes:

=====================================
modules/services_discovery/bonjour.m
=====================================
@@ -32,6 +32,7 @@
 #include <vlc_renderer_discovery.h>
 
 #import <Foundation/Foundation.h>
+#import <arpa/inet.h>
 
 #pragma mark Function declarations
 
@@ -122,6 +123,43 @@ NSString *const VLCBonjourRendererDemux         = @"VLCBonjourRendererDemux";
 
 @end
 
+static NSString * ipAddressAsStringForData(NSData * data)
+{
+    char addressBuffer[INET6_ADDRSTRLEN] = { 0 };
+    NSString *returnValue = nil;
+
+    if (data == nil) {
+        return returnValue;
+    }
+
+    typedef union {
+        struct sockaddr sa;
+        struct sockaddr_in ipv4;
+        struct sockaddr_in6 ipv6;
+    } ip_socket_address;
+
+    ip_socket_address *socketAddress = (ip_socket_address *)[data bytes];
+
+    if (socketAddress) {
+        const char *addressStr;
+        if (socketAddress->sa.sa_family == AF_INET) {
+            addressStr = inet_ntop(socketAddress->sa.sa_family,
+                                           (void *)&(socketAddress->ipv4.sin_addr),
+                                           addressBuffer,
+                                           sizeof(addressBuffer));
+        } else if (socketAddress->sa.sa_family == AF_INET6) {
+            addressStr = inet_ntop(socketAddress->sa.sa_family,
+                                           (void *)&(socketAddress->ipv6.sin6_addr),
+                                           addressBuffer,
+                                           sizeof(addressBuffer));
+        }
+        if (addressStr != NULL) {
+            returnValue = [NSString stringWithUTF8String:addressStr];
+        }
+    }
+    return returnValue;
+}
+
 @implementation VLCNetServiceDiscoveryController
 
 - (instancetype)initWithRendererDiscoveryObject:(vlc_renderer_discovery_t *)p_rd
@@ -376,8 +414,13 @@ NSString *const VLCBonjourRendererDemux         = @"VLCBonjourRendererDemux";
 - (void)addResolvedInputItem:(NSNetService *)netService withProtocol:(NSString *)protocol
 {
     services_discovery_t *p_sd = (services_discovery_t *)_p_this;
+    NSString *host = netService.hostName;
+
+    if ([protocol isEqualToString:@"smb"]) {
+        host = ipAddressAsStringForData(netService.addresses.firstObject);
+    }
+    NSString *uri = [NSString stringWithFormat:@"%@://%@:%ld", protocol, host, netService.port];
 
-    NSString *uri = [NSString stringWithFormat:@"%@://%@:%ld", protocol, netService.hostName, netService.port];
     input_item_t *p_input_item = input_item_NewDirectory([uri UTF8String], [netService.name UTF8String], ITEM_NET );
     if (p_input_item != NULL) {
         services_discovery_AddItem(p_sd, p_input_item);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d4c8f5c0ea25f305e36c890f1da3335f961dd75a

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d4c8f5c0ea25f305e36c890f1da3335f961dd75a
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list