*/
function mapIp($ip)
{
+ if (strpos($ip, ':') !== false) {
+ return mapIpv6($ip);
+ }
+
$private = substr($ip, 0, 3) == '10.'
|| substr($ip, 0, 7) == '172.16.'
|| substr($ip, 0, 7) == '172.17.'
}
return $ip;
}
+
+/**
+ * Map IPv6 addresses to their 64bit prefix, assuming that the PC and the OUYA
+ * share the same prefix.
+ * Map local IPs to a single IP so that this the queue can be used
+ * in the home network.
+ *
+ * @see RFC 6890: Special-Purpose IP Address Registries
+ * @see RFC 4291: IP Version 6 Addressing Architecture
+ * @link https://en.wikipedia.org/wiki/Link-local_address
+ */
+function mapIpv6($ip)
+{
+ $ip = strtolower(expandIpv6($ip));
+ if ($ip == '0000:0000:0000:0000:0000:0000:0000:0001') {
+ //localhost
+ return 'local';
+ } else if (substr($ip, 0, 2) == 'fc' || substr($ip, 0, 2) == 'fd') {
+ // fc00::/7 = Unique Local Unicast
+ return 'local';
+ } else if (substr($ip, 0, 3) == 'fe8'
+ || substr($ip, 0, 3) == 'fe9'
+ || substr($ip, 0, 3) == 'fea'
+ || substr($ip, 0, 3) == 'feb'
+ ) {
+ // fe80::/10 = Link-Local unicast
+ return 'local';
+ }
+
+ return substr($ip, 0, 19);
+}
+
+function expandIpv6($ip)
+{
+ $hex = unpack("H*hex", inet_pton($ip));
+ return implode(':', str_split($hex['hex'], 4));
+}
echo 'Cannot detect your IP address' . "\n";
exit(1);
}
-if (strpos($ip, ':') !== false) {
- header('HTTP/1.0 400 Bad Request');
- header('Content-type: text/plain');
- echo 'Sorry, IPv6 is not supported' . "\n";
- echo 'This here only works if the OUYA and your PC have the same IP address,'
- . "\n";
- echo 'and this is definitely not the case when using IPv6' . "\n";
- exit(1);
-}
$ip = mapIp($ip);
try {