Merge "Fix DIAL multicast registering (b/29832085)"
diff --git a/src/server/main.c b/src/server/main.c
index 33e83dc..6e4d464 100644
--- a/src/server/main.c
+++ b/src/server/main.c
@@ -140,6 +140,24 @@
  * End of URL ENCODE source
  */
 
+// Returns 0 for false, non-zero for true.
+static int isWirelessTV() {
+  FILE* fp;
+  char active_wan[6];
+
+  fp = popen("activewan", "r");
+  if (fp == NULL) {
+    fprintf(stderr, "Could not run activewan; assuming wired connection\n");
+    return 0;
+  }
+
+  fgets(active_wan, sizeof(active_wan) - 1, fp);
+  pclose(fp);
+
+  return strncmp(active_wan, "wcli0", 5) == 0 ||
+         strncmp(active_wan, "wcli1", 5) == 0;
+}
+
 /*
  * This function will walk /proc and look for the application in
  * /proc/<PID>/comm. and /proc/<PID>/cmdline to find it's command (executable
@@ -277,7 +295,9 @@
     fprintf(stderr, "** LAUNCH YouTube ** with args %s\n\n", args);
 
     char url[512] = {0,};
-    int urlLength = snprintf( url, sizeof(url), "https://www.youtube.com/tv?%s", args);
+    int urlLength =
+        snprintf(url, sizeof(url), "https://www.youtube.com/tv?%s&%s",
+                 isWirelessTV() ? "wireless" : "wired", args);
     if (urlLength>=sizeof(url)) {
       fprintf(stderr, "Warning, YouTube URL was truncated (%d>=%d)\n", urlLength, sizeof(url));
     }