Skip to content
Snippets Groups Projects
Commit 2d52141e authored by Felix Paul Kühne's avatar Felix Paul Kühne Committed by Rémi Denis-Courmont
Browse files

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
parent 27948cbf
No related branches found
No related tags found
1 merge request!1725bonjour SD: resolve hostname to IP for SMB
Pipeline #209308 passed with stages
in 35 minutes and 53 seconds
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <vlc_renderer_discovery.h> #include <vlc_renderer_discovery.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <arpa/inet.h>
#pragma mark Function declarations #pragma mark Function declarations
...@@ -120,6 +121,43 @@ NSString *const VLCBonjourRendererDemux = @"VLCBonjourRendererDemux"; ...@@ -120,6 +121,43 @@ NSString *const VLCBonjourRendererDemux = @"VLCBonjourRendererDemux";
@end @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 @implementation VLCNetServiceDiscoveryController
- (instancetype)initWithRendererDiscoveryObject:(vlc_renderer_discovery_t *)p_rd - (instancetype)initWithRendererDiscoveryObject:(vlc_renderer_discovery_t *)p_rd
...@@ -374,8 +412,13 @@ NSString *const VLCBonjourRendererDemux = @"VLCBonjourRendererDemux"; ...@@ -374,8 +412,13 @@ NSString *const VLCBonjourRendererDemux = @"VLCBonjourRendererDemux";
- (void)addResolvedInputItem:(NSNetService *)netService withProtocol:(NSString *)protocol - (void)addResolvedInputItem:(NSNetService *)netService withProtocol:(NSString *)protocol
{ {
services_discovery_t *p_sd = (services_discovery_t *)_p_this; 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 ); input_item_t *p_input_item = input_item_NewDirectory([uri UTF8String], [netService.name UTF8String], ITEM_NET );
if (p_input_item != NULL) { if (p_input_item != NULL) {
services_discovery_AddItem(p_sd, p_input_item); services_discovery_AddItem(p_sd, p_input_item);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment