浏览代码

make AirPlay work in AP mode

philippe44 5 年之前
父节点
当前提交
1a5f5283bb
共有 3 个文件被更改,包括 28 次插入9 次删除
  1. 6 0
      components/raop/raop.c
  2. 1 1
      components/raop/raop_sink.c
  3. 21 8
      components/raop/util.c

+ 6 - 0
components/raop/raop.c

@@ -436,6 +436,12 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
 		char *buf_pad, *p, *data_b64 = NULL, data[32];
 
 		LOG_INFO("[%p]: challenge %s", ctx, buf);
+		
+		// try to re-acquire IP address if we were missing it
+		if (S_ADDR(ctx->host) == INADDR_ANY) {
+			S_ADDR(ctx->host) = get_localhost(NULL);
+			LOG_INFO("[%p]: IP was missing, trying to get it %s", ctx, inet_ntoa(ctx->host));
+		}
 
 		// need to pad the base64 string as apple device don't
 		base64_pad(buf, &buf_pad);

+ 1 - 1
components/raop/raop_sink.c

@@ -163,7 +163,7 @@ void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
     	free(sink_name_buffer);
     }
 
-	LOG_INFO( "mdns hostname set to: [%s] with servicename %s", hostname, sink_name);
+	LOG_INFO( "mdns hostname for ip %s set to: [%s] with servicename %s", inet_ntoa(host), hostname, sink_name);
 
     // create RAOP instance, latency is set by controller
 	uint8_t mac[6];	

+ 21 - 8
components/raop/util.c

@@ -23,12 +23,7 @@
 #ifdef WIN32
 #include <iphlpapi.h>
 #else
-/*
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <netdb.h>
-*/
+#include "tcpip_adapter.h"
 #include <ctype.h>
 #endif
 
@@ -84,8 +79,26 @@ in_addr_t get_localhost(char **name)
 	}
 	else return INADDR_ANY;
 #else
-	// missing platform here ...
-	return INADDR_ANY;
+	tcpip_adapter_ip_info_t ipInfo; 
+	tcpip_adapter_if_t if_type = TCPIP_ADAPTER_IF_STA;
+
+	// then get IP address
+ 	tcpip_adapter_get_ip_info(if_type, &ipInfo);
+	
+	// we might be in AP mode
+	if (ipInfo.ip.addr == INADDR_ANY) {
+		if_type = TCPIP_ADAPTER_IF_AP;
+		tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ipInfo);
+	}
+
+	// get hostname if required
+	if (name) {
+		const char *hostname;
+		tcpip_adapter_get_hostname(if_type, &hostname);
+		*name = strdup(hostname);
+	}	
+
+	return ipInfo.ip.addr;
 #endif
 }