From 1a5f5283bb711d953909392fb55a72fd8f319cff Mon Sep 17 00:00:00 2001 From: philippe44 Date: Sun, 8 Mar 2020 16:51:24 -0700 Subject: [PATCH] make AirPlay work in AP mode --- components/raop/raop.c | 6 ++++++ components/raop/raop_sink.c | 2 +- components/raop/util.c | 29 +++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/components/raop/raop.c b/components/raop/raop.c index a01303e1..2d989a86 100644 --- a/components/raop/raop.c +++ b/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); diff --git a/components/raop/raop_sink.c b/components/raop/raop_sink.c index 1424e94f..73b711f5 100644 --- a/components/raop/raop_sink.c +++ b/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]; diff --git a/components/raop/util.c b/components/raop/util.c index 13744409..f2a9be77 100644 --- a/components/raop/util.c +++ b/components/raop/util.c @@ -23,12 +23,7 @@ #ifdef WIN32 #include #else -/* -#include -#include -#include -#include -*/ +#include "tcpip_adapter.h" #include #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 }